Write a Java Program to Generate Multiplication Table

Multiplication tables are a fundamental concept in mathematics, and it’s crucial to understand them for various purposes.

In this tutorial, we will discuss how to create a Java program that generates a multiplication table for a given number.


To begin with, we will prompt the user to enter the number they want to generate the multiplication table for using the Scanner class.

After the user inputs the number, we will loop through the table and print each result to the console.

Here’s the Java code that accomplishes this task:

import java.util.Scanner;

public class MultiplicationTable {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number to generate its multiplication table: ");
        int number = scanner.nextInt();

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

In the code above, we first import the Scanner class, which allows us to read user input from the console.

We then prompt the user to enter a number, which we store in the number variable.

Next, we use a for loop to generate the multiplication table.

The loop will iterate 10 times, as we are generating a table up to 10. For each iteration, we print the multiplication result to the console using the System.out.println() method.

The output includes the input number, the current iteration value, and the result of multiplying the two.

Once the program finishes executing, it will print the multiplication table for the user’s input number.


In conclusion, generating a multiplication table in Java is a simple task that can be accomplished with a few lines of code.

With this program, you can easily generate multiplication tables for any number up to 10.