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
how to one war file class to another war file class?
Explain when we should make an instance variable private.
Explain about serializable interface in java?
Why does java have different data types for integers and floating-point values?
Why string is immutable with example?
What are the differences between abstract class and interface?
Is alive method in java?
Can we override constructor in java?
Explain the difference between an Interface and an Abstract class?
What is meant by class loader? How many types are there? When will we use them?
What is java string pool?
What is advantage of java?
What is the set interface in java programming?
What are the basic control structures?
How does remove work in java?