Tell me the programme for this


@
1 2
@ @ @
1 2 3 4

Answer Posted / chantiraji

public class TriangleDisplay {

public static void main(String[] args) {
int n = 4;
for (int i = 1; i <= n; i++) {
for (int j = 4; 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 ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is use of static in java?

535


What is Java Annotations?

557


Explain about assignment statement?

599


What is multiple inheritance? Is it supported by java?

530


What is unicode full form?

556






What is the difference between private & public & friendly classes?

554


What are keywords in programming?

569


How big is a boolean?

583


What is the set interface in java programming?

631


Can we assign the reference to this variable?

549


Why isn’t there operator overloading?

598


Why scanner is used in java?

552


How many ways can we create the string object?

532


Explain what is encapsulation?

609


How many static init can you have?

685