Java Program to print Multiplication table of a given number


In this post, let's learn how to print multiplication table of a given number.

Java program to generate multiplication table:

import java.util.Scanner;

public class Multiplication {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
    	  System.out.println("Enter an integer: ");
    	  int num = input.nextInt(); // read input from User
    	  
        for(int i = 1; i <= 10; i++) // Iterate for loop for 10 times
        {
            System.out.printf("%d * %d = %d \n", num, i, num * i);
        }
    }
}

Result

Consider you have provided 16 as your input, then below is the output

16 * 1 = 16 
16 * 2 = 32 
16 * 3 = 48 
16 * 4 = 64 
16 * 5 = 80 
16 * 6 = 96 
16 * 7 = 112 
16 * 8 = 128 
16 * 9 = 144 
16 * 10 = 160

If you want to generate the multiplication table to other range like 20, provide i<=20 in the for loop condition which generates the output as below.

16 * 1 = 16 
16 * 2 = 32 
16 * 3 = 48 
16 * 4 = 64 
16 * 5 = 80 
16 * 6 = 96 
16 * 7 = 112 
16 * 8 = 128 
16 * 9 = 144 
16 * 10 = 160 
16 * 11 = 176 
16 * 12 = 192 
16 * 13 = 208 
16 * 14 = 224 
16 * 15 = 240 
16 * 16 = 256 
16 * 17 = 272 
16 * 18 = 288 
16 * 19 = 304 
16 * 20 = 320

Try yourself here by providing the integer value in the stdin section.