Java program to print a multiplication table for any number


Following is a Java program which accepts an integer variable from user and prints the multiplication table of that particular integer.

Example

import java.util.Scanner;
public class MultiplicationTable {
   public static void main(String args[]) {
      System.out.println("Enter an integer variable :: ");
      Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      for(int i=1; i<= 20; i++) {
         System.out.println(""+num+" X "+i+" = "+(num*i));
      }
   }
}

Output

Enter an integer variable ::
17
17 X 1 = 17
17 X 2 = 34
17 X 3 = 51
17 X 4 = 68
17 X 5 = 85
17 X 6 = 102
17 X 7 = 119
17 X 8 = 136
17 X 9 = 153
17 X 10 = 170
17 X 11 = 187
17 X 12 = 204
17 X 13 = 221
17 X 14 = 238
17 X 15 = 255
17 X 16 = 272
17 X 17 = 289
17 X 18 = 306
17 X 19 = 323
17 X 20 = 340

Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements