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
Write a program to print fibonacci series
What is singleton class in java and how can we make a class singleton?
What are internal variables?
EDS (Electronic Data Systems India Pvt Ltd) at Chennai on 16-12-2006.
What is instance example?
What are the ways in which a thread can enter the waiting state?
Can we have multiple classes in single file ?
What are the restrictions imposed by a Security Manager on Applets?.
what is meant by encapsulation?
How to use Media tracker Class.
Explain the selection sort algorithm and state its time complexity?
Explain a few methods of overloading best practices in java?
What does java se mean?
What is javac_g?
What are different types of inner classes ?