Try building this yourself before looking at the solution. Print a multiplication table for the numbers through .
Expected output:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Here is one solution using nested for loops:
for (int row = 1; row <= 5; row++) {
for (int col = 1; col <= 5; col++) {
System.out.print(row * col + " ");
}
System.out.println();
}
The outer loop picks the row. The inner loop picks the column. You multiply them and print the result. The tab character aligns the columns. After each complete inner loop, println() moves to the next line.