You're pretty close, just a little off with the logic in your nested loop. This is what I modified:
1) Moved the column label outside the inner loop
2) Created a counter to use for the cell values
3) Use the counter to print the cell value & then incremented it
Code:
String headerRow= " * |";
String spacer = "-----";
for(int i=1; i<secondInt + 1; i++){headerRow+=" "+i; spacer+="----";}
System.out.println(headerRow);
System.out.println(spacer);
int counter = 1;
for (int i = 1; i < firstInt + 1; i++) {
System.out.printf("%4s", i + " |");
for (int j = 1; j < secondInt + 1; j++) {
System.out.printf("%4d", counter);
counter++;
}
System.out.println();
}
That code outputs this:
> 4 5 numbers
* | 1 2 3 4 5
> -------------------------
1 | 1 2 3 4 5
2 | 6 7 8 9 10
3 | 11 12 13 14 15
4 | 16 17 18 19 20