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 ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which variables are stored in stack?

453


Can a vector contain heterogenous objects?

608


What is classes in java?

523


How to reverse a string in java?

527


How do you break a loop?

568






What are the data types supported by java? What is autoboxing and unboxing?

552


Which method must be implemented by all threads?

728


Can a method inside a interface be declared as final?

534


What is the set interface in java programming?

631


What are the main differences between notify and notifyAll in Java?

587


Is java owned by oracle?

528


worst case complexities of Quick sort and Merge sort.

611


Can we use this () and super () in a method?

535


What is boolean used for?

594


What will be the default values of all the elements of an array defined as an instance variable?

562