Java Program to Generate Multiplication Table

Java Program to Generate Multiplication Table

In this program, you'll learn to generate multiplication table of a given number. This is done by using a for and a while loop in Java.

Example 1: 

public class MultiplicationTable {

    public static void main(String[] args) {

        int num = 7;
        for(int i = 1; i <= 10; ++i)
        {
            System.out.printf("%d * %d = %d \n", num, i, num * i);
        }
    }
}

Output :

7 * 1 = 7 
7 * 2 = 14 
7 * 3 = 21 
7 * 4 = 28 
7 * 5 = 35 
7 * 6 = 42 
7 * 7 = 49 
7 * 8 = 56 
7 * 9 = 63 
7 * 10 = 70

 

Example 2: 

public class MultiplicationTable {

    public static void main(String[] args) {

        int num = 11, i = 1;
        while(i <= 10)
        {
            System.out.printf("%d * %d = %d \n", num, i, num * i);
            i++;
        }
    }
}

Output :

11 * 1 = 11 
11 * 2 = 22 
11 * 3 = 33 
11 * 4 = 44 
11 * 5 = 55 
11 * 6 = 66 
11 * 7 = 77 
11 * 8 = 88 
11 * 9 = 99 
11 * 10 = 110                 


Subscribe For Daily Updates

JAVA File IO examples

JAVA Date & Time Progamming Examples

JAVA Collections

Flutter Questions
Android Questions