You are here

Java program to print multiplication table

Java program to print multiplication table of a number entered by a user using a for loop. You can modify it for while or do while loop for practice. Using nested loops (a loop inside another loop), we can print tables of numbers between a given range say a to b, for example, if the input numbers are '3' and '6' then tables of '3', '4', '5' and '6' will be printed.

Java programming source code

  1. import java.util.Scanner;
  2.  
  3. class MultiplicationTable
  4. {
  5.   public static void main(String args[])
  6.   {
  7.     int n, c;
  8.     System.out.println("Enter an integer to print it's multiplication table");
  9.     Scanner in = new Scanner(System.in);
  10.     n = in.nextInt();
  11.     System.out.println("Multiplication table of " + n);
  12.  
  13.     for (c = 1; c <= 10; c++)
  14.       System.out.println(n + "*" + c + " = " + (n*c));
  15.   }
  16. }

Output of program:
Java program to print multiplication table output

Download Multiplication table program class file.

Code:

  1. import java.util.Scanner;
  2.  
  3. class Tables
  4. {
  5.   public static void main(String args[])
  6.   {
  7.     int a, b, c, d;
  8.  
  9.     System.out.println("Enter range of numbers to print their multiplication tables");
  10.     Scanner in = new Scanner(System.in);
  11.  
  12.     a = in.nextInt();
  13.     b = in.nextInt();
  14.  
  15.     for (c = a; c <= b; c++) {
  16.       System.out.println("Multiplication table of "+c);
  17.  
  18.       for (d = 1; d <= 10; d++) {
  19.         System.out.println(c+"*"+d+" = "+(c*d));
  20.       }
  21.     }
  22.   }
  23. }