This isn't homework, it's a question in a textbook practice example that I can't seem to get right.
I got it to work with 3 for loops, but I don't know how to get it to work with 2 for loops and a if statement.
Can someone show me how to get the following :
/* *Write a nested for loop to display the following matrix: *1 2 3 4 * 1 2 3 * 1 2 * 1 * basically they just increase by 2 spaces every iteration it seems like. */ //this is as much of a layout of my code i can do for (int i = 1; i <= 4; i++) { for (int j = 1; j <= 5 - i; j++) { //i have a feeling the if statement should go after the 2nd for loop, but i can't get it to work. System.out.print(j + " "); } System.out.println(); }