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 an example of a keyword?
What do you mean by ternary operator in java?
When should we create our own custom exception classes?
What is the biggest integer?
What are the benefits of operations in java?
What is internal variable?
How does hashset work in java?
In a container there are 5 components. I want to display all the component names, how will you do that?
Can a source file contain more than one class declaration?
Explain exception chaining in java?
How many types of string data types are there?
what is an objects lock and which objects have locks? : Java thread
what is object-oriented programming in java?
Are floats faster than doubles?
What is the default value of local and global variables?