Skip to main content

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:

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. }

Comments

Popular posts from this blog

Java while loop

Java while loop Java while loop is used to execute statement(s) until a condition is true. In this tutorial, we will learn to use while loop with examples. First of all, let's discuss while loop syntax: while (condition(s)) { // Body of loop } 1. If the condition(s) holds true then the body of the loop is executed, after execution of the loop body condition is tested again and if the condition is still true then the body of the loop is executed again, and the process repeats until the condition(s) becomes false. The condition evaluates to true or false and if it is a constant, for example, while (c) {…}, where c is a constant, then any non zero value of c is considered to be true, and zero is considered false. 2. You can test multiple conditions such as while   ( a  >  b  &&  c  !=   0 )   {   // Loop body } Loop body is executed till value of variable a is greater than value of...

Install & Use Gujrati Indic Input Font | સરળ છે ગુજરાતી ઈન્ડિક ઇન્પુટ (શ...