Java program to generate multiplication table

How to generate multiplication table in java?

In this program, we will understand the logic to print table and also implement that logic in java programs.

A table is a sequence of number that are generated using multiplication. We enter an integer as input of which we want to print the table. After that, we multiply the entered by 1 to 10, respectively on by one.

Suppose we have entered 5 as input then the table of 5 will be:

5*1 = 5
5*2= 10
5*3 =15

  • Program:

public class MultiplicationTable {

    public static void main(String[] args) {

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

  • Output:

8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64 8 * 9 = 72 8 * 10 = 80



0 comments