how to print the below in java?thanks in advance....
*
* *
* *
* *
*
Answer Posted / keerthi
public class Diamond{
public static void main(String args[]){
int n=10;
int m=n/2;
int p=0;
for(int i=0; i<=n;i++){
if(i>m)
p++;
for(int j=0; j<=n;j++){
if((m-i)==j ||(m+i)==j || (i-j)==m ||(i>m && (n-p)==j))
System.out.print("*");
else
System.out.print(" ");
}
System.out.println("\n");
}//First for loop end
}//Main
}//Class end
output:
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
| Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
Are generics important java?
What are constants?
What is method and methodology?
Can a class have a static inner class?
Is java a prime method?
What is the purpose of using java.lang.class class?
What is data type in computer?
Can a list be null in java?
What happens if constructor is private?
What is square root in java?
How to display all the prime numbers between 1 and n (n is the number, get the input from user)
Why are data types important?
What is difference between equal and == in java?
Can we sort set in java?
What do you mean by Hash Map and Hash Table?