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 do you understand by synchronization? Or what is synchronization and why is it important? Or describe synchronization in respect to multithreading? Or what is synchronization? : Java thread

0 Answers  


whays is mean by inner class?

4 Answers   HCL, IBM, TCS,


What is the difference between object oriented programming language and object based programming language?

0 Answers  


What best practices should you follow while writing multithreaded code in java?

0 Answers  


What are methods of a class?

0 Answers  






Nullpointer exception is a very common exception. Why is it not made as a checked exception?

2 Answers   Ness Technologies,


What are actual parameters?

0 Answers  


Difference between String & StringBuffer

16 Answers   IBM, Infosys, Tech Mahindra, Wipro,


What is the use of singleton class?

0 Answers  


What is the order of arraylist in java?

0 Answers  


What is collection class in java?

0 Answers  


What is assembly condition codes?

0 Answers  


Categories