I'm a beginner to Java and can't figure out how to print an upside down triangle of numbers. The numbers should decrease in value by 1 for each row. Ex. Number of rows: 6
;
Print:
666666
55555
4444
333
22
1
So far this is what I came up with; (int nr
is scanned input from user)
for (int i = 1; i <= nr; i++) {
for (int j = 1; j <= nr; j++) {
System.out.print(nr);
}
nr--;
System.out.println();
}
By having nr--;
the loop gets shorter and I cant figure out how to keep the loop going for nr
-times, yet still decreasing the amount of numbers printed out.