Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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

Define interface in java?

0 Answers  


Is 'null' a keyword?

8 Answers  


Explain the protected field modifier?

0 Answers  


How do you create a null object?

0 Answers  


What is the significance of continue jump statement? Explain with an example.

0 Answers   Amdocs,






What is vector?

0 Answers  


Is java type safe?

0 Answers  


Where is singleton pattern used?

0 Answers  


what is object slice?

2 Answers   HTC, TCS,


Can an interface extend another interface?

0 Answers  


can u handle an error if u write Thowable in the catch class lise try { some errorneous code }catch(Throwable e){ ...}

4 Answers  


What is the advantage of preparedstatement over statement?

0 Answers  






Categories