Multiplication Table in Java: Explanation & Practice

Print multiplication table for a number

Problem summary

Print the multiplication table for 5 (5x1 through 5x5).

Starter code

public class Main {
    public static void main(String[] args) {
        int num = 5;
        
        // Print: 5 x 1 = 5, 5 x 2 = 10, etc.
    }
}

Expected output and test cases

  • 5x table (1-5)
    5 x 1 = 5
    5 x 2 = 10
    5 x 3 = 15
    5 x 4 = 20
    5 x 5 = 25

Hints

  1. Use a for loop from 1 to 5
  2. Calculate product: num * i
  3. Print in format: num x i = product

Related Control Flow exercises

Practice all Control Flow exercises · Run this idea in the Java compiler