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
What are mutable classes?
Is a char always 1 byte?
What do you mean by default constructor in java?
How are this() and super() used with constructors in java programming?
What is data string?
What is return keyword in java?
What are the advantages and disadvantages of object cloning?
What is the effect of keeping a constructor private?
Is null function in java?
What is the use of hashmap in java?
What is the integer of 16?
What is the difference between member variables initialization and assignment in a constructor?
What is the constructor?
what invokes a threads run() method? : Java thread
How do you identify if jvm is 32-bit or 64-bit from java program?