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 are mutable classes?

521


Is a char always 1 byte?

505


What do you mean by default constructor in java?

576


How are this() and super() used with constructors in java programming?

570


What is data string?

495






What is return keyword in java?

559


What are the advantages and disadvantages of object cloning?

568


What is the effect of keeping a constructor private?

471


Is null function in java?

564


What is the use of hashmap in java?

550


What is the integer of 16?

537


What is the difference between member variables initialization and assignment in a constructor?

662


What is the constructor?

581


what invokes a threads run() method? : Java thread

572


How do you identify if jvm is 32-bit or 64-bit from java program?

536