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


Please Help Members By Posting Answers For Below Questions

what is difference between equals and ==?

592


What is meant by data hiding/encapsulation?

577


How does multithreading take place on a computer with a single cpu?

551


Can we override the overloaded method?

568


What is meant by data hiding in java?

640






Should a main method be compulsorily declared in all java classes?

536


What is jit compiler ?

580


What is a variable analysis?

642


Is java a prime method?

555


Difference between == and .equals() ?

579


How we create object in copy constructor?

650


What are the wrapped, classes?

601


What do you mean by hashing?

647


What is the set interface in java programming?

631


What are different types of multitasking?

551