Java Program to Generate Multiplication Table

If you are new to Java and want to learn the java coding skills too fast. Try practicing the core java programs with the help of the Java basic programs list available.

Program to Generate Multiplication Table

In this article we will see how we can generate multiplication table.

Multiplication Table is something which produces result of multiplication of a single number with other numbers starting from 1 to 10 generally. But multiplication also possible with other numbers after 10.

For example :

  This is the multiplication table of 7.  
    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

We will see two different approaches to get the multiplication table of a number.

Note: In this article we will see getting multiplication table upto 10.

Method-1 : By using for loop

By using for loop we can get the multiplication number.

Approach:

  • Take a number(static input or dynamic input)
  • Multiply the number with 1 to 10 by looping.
  • For looping from 1 to 10 for loop used.
  • Print the multiplication result one by one.
class Multiplication 
{
    public static void main(String[] args)
    {
        // This is the number of which we will get the multiplication table.
        int num = 6;
  
        // We will get the multiplication table from 1 to 10 
        // Here for loop used for looping
        for (int i = 1; i <= 10; i++) 
        {
            // printing num*i
            // where 'i' is the ith multiplication
            System.out.println(num + " * " + i + " = " + num * i);
        }
    }
}
Output:

6 * 1 = 6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
6 * 10 = 60

CASE-2
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

Method-2 : By using for loop

By using for loop we can get the multiplication number.

Approach:

  • Take a number(static input or dynamic input)
  • Multiply the number with 1 to 10 by looping.
  • For looping from 1 to 10 while loop used.
  • Print the multiplication result one by one.
class Multiplication 
{
    public static void main(String[] args)
    {
        // This is the number of which we will get the multiplication table.
        int num = 4;
        int i=1;
  
        // We will get the multiplication table from 1 to 10 
        // Here while loop used for looping
        while(i <= 10)
        {
            // printing num*i
            // where 'i' is the ith multiplication
            System.out.println(num + " * " + i + " = " + num * i);
            // incrementing i
            i++;
        }
    }
}
Output:

4 * 1 = 4
4 * 2 = 8
4 * 3 = 12
4 * 4 = 16
4 * 5 = 20
4 * 6 = 24
4 * 7 = 28
4 * 8 = 32
4 * 9 = 36
4 * 10 = 40

CASE-2
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Get started with learning the programming language Java from beginner to experienced level by referring to our collection of Java Programs with Source Code and become a pro in the subject.

Related Java Decision Making and Loop Programs: