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
Is ++ operator is thread safe in java?
What is application system?
What is the constructor?
What are synchronized methods and synchronized statements in java programming?
List some features of the abstract class.
Give few examples of final classes defined in Java API?
What is default constructors?
what are Hostile Applets?
What are constants and how to create constants in java?
Can you use this() and super() both in a constructor?
What is singleton class in ruby?
What is the difference between scrollbar and scrollpane?
What is the driver class?
What is an abstract class and what is it’s purpose?
What is return in java?