how to print the below in java?thanks in advance....
*
* *
* *
* *
*

Answers were Sorted based on User's Feedback



how to print the below in java?thanks in advance.... * * ..

Answer / 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

how to print the below in java?thanks in advance.... * * ..

Answer / venkat

In the above program 4th line from last remove "\n"
ie. shoule be System.out.println("")

below is output:


*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*

Is This Answer Correct ?    1 Yes 1 No

how to print the below in java?thanks in advance.... * * ..

Answer / jitendra

for(i=1;i<=3;i++)
{
for(j=3;j>=i;j--)
System.out.printf(" ");
System.out.printf("*");
for(j=1;j<2+i;j++)
System.out.printf(" ");
System.out.printf("*");
System.out.printf("\n");
}
this is to print
*
* *
* *
now apply ur brain to print the rest...
any problem ..then mail me
jitendrasharma13@gmail.com

Is This Answer Correct ?    2 Yes 6 No

Post New Answer

More Core Java Interview Questions

What is double in java?

0 Answers  


What are class members by default?

0 Answers   Hexaware,


How we can generate random numbers in java?

0 Answers  


What are dot operator queries?

0 Answers   Atos Origin,


Is arraylist zero based?

0 Answers  






what is the difference between a java object reference and c++ pointer?

4 Answers  


Why do we create public static method in java?

0 Answers  


what is object-oriented programming in java?

0 Answers   Reliance,


How java is similar to c?

0 Answers  


os is developed in c no java is more secured then c na why dont the os developed is developed using java

1 Answers  


How do you sort a list in java?

0 Answers  


whats the diff between jsp and servlets?

9 Answers   HCL, TCS,


Categories