Tell me the programme for this


@
1 2
@ @ @
1 2 3 4

Answer Posted / thati.donthi

public class PrintTriangle {

public static void main(String[] args) {
int n=4;
for(int i=1;i<=n;i++) {
for(int j=0;j<2*n-i;j++) {
System.out.print(" ");
}
for(int j=1;j<=i;j++) {
if(i%2 != 0) {
System.out.print("@"+" ");
} else {
System.out.print(j+" ");
}
}
System.out.println();
}
}
}

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How dead lock situation occurs in java and how you can identify it?

547


What is treeset in java collection?

529


Can a method inside a interface be declared as final?

532


what is the volatile modifier for? : Java thread

523


What is += mean in java?

546






Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?

563


What is the flag in java?

612


why doesn't java run on all platforms?

571


How do you replace a string in java?

548


How do you sing an Applet ?

2039


What exceptions occur during serialization?

612


How do you clear a method in java?

544


What is anonymous inner class?

611


How can we find the sum of two linked lists using stack in java?

574


What access modifiers can be used for variables?

589