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

how to one war file class to another war file class?

1552


Explain when we should make an instance variable private.

610


Explain about serializable interface in java?

584


Why does java have different data types for integers and floating-point values?

535


Why string is immutable with example?

528






What are the differences between abstract class and interface?

513


Is alive method in java?

508


Can we override constructor in java?

579


Explain the difference between an Interface and an Abstract class?

629


What is meant by class loader? How many types are there? When will we use them?

509


What is java string pool?

545


What is advantage of java?

542


What is the set interface in java programming?

627


What are the basic control structures?

501


How does remove work in java?

523