Multiplication Grid 15
This program prints multiplication grid from 1 to 5 using nested for loop.
Problem Statement
Write a Java program that prints multiplication grid from 1 to 5 using nested for loop.
Source Code
| 1 | public class MultiplicationGrid { |
| 2 | public static void main(String[] args) { |
| 3 | for(int i=1; i<=5; i++) { |
| 4 | for(int j=1; j<=5; j++) { |
| 5 | System.out.print((i*j) + "\t"); |
| 6 | } |
| 7 | System.out.println(); |
| 8 | } |
| 9 | } |
| 10 | } |
Program 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
Explanation
The outer loop controls rows, inner loop prints product of row and column indices. - This demonstrates nested loops for multiplication grids. Conclusion: Shows how nested for loops can generate multiplication grids.