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
How do you write methodology?
What is final class?
What is meant by nested loop?
How can an object be unreferenced?
What is jrmp?
what is collatration?
Can a singleton class be inherited?
Are maps ordered java?
What is bitwise complement?
What is ctrl m character?
What is the applet security manager, and what does it provide?
What does system out println () do?
Explain importance of inheritance in java?
what happens when a thread cannot acquire a lock on an object? : Java thread
Explain the selection sort algorithm?