[Solved] triangle of square numbers java


Only the second inner loop needs to be adjusted a little bit (changes in bold):

for (int k = i; k >= 1; k--) {
    System.out.printf("  %2d", k * k);
}

The first inner loop for indention runs n-i times, so the second inner loop have to do the rest: i..1.

And you have to print the square of the inner loop variable k instead of the outer loop variable i (which does not change in the inner loop).

solved triangle of square numbers java