java

Java Program to Print Multiplication Table

In this tutorial, we are going to see how to write a Java program to print the multiplication table.
 

Java Program to Print Multiplication Table:

The following example displays the multiplication table of a number entered by the user using a for loop.

import java.util.Scanner;

class Main
{
  public static void main(String args[])
  {
    int nbr, i;
    System.out.print("Enter a number to display its multiplication table: ");
    Scanner sc = new Scanner(System.in);
    nbr = sc.nextInt();
	
    System.out.println("Multiplication table of " + nbr);

    for (i = 1; i <= 10; i++)
      System.out.println(nbr + " x " + i + " = " + (nbr * i));
  }
}

Output:

Enter a number to display its multiplication table: 2
Multiplication table of 2
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *