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 is difference between equals and ==?
What is meant by data hiding/encapsulation?
How does multithreading take place on a computer with a single cpu?
Can we override the overloaded method?
What is meant by data hiding in java?
Should a main method be compulsorily declared in all java classes?
What is jit compiler ?
What is a variable analysis?
Is java a prime method?
Difference between == and .equals() ?
How we create object in copy constructor?
What are the wrapped, classes?
What do you mean by hashing?
What is the set interface in java programming?
What are different types of multitasking?