In this tutorial, we will write a Java program to print a multiplication table for any number. Before that, you may go through the following topic in java.
Java Program to Print Multiplication Table using for loop
Source code: The user needs to enter the number for which the table is to be printed and a program using for loop prints the multiplication table for that number.
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number:");
int num = sc.nextInt();
System.out.println("Multiplication table for " + num + " number:");
for (int i = 1; i <= 10; i++)
System.out.println(num + " *" + i + " = " + num *i);
}
}
Output:
Enter the number:2
Multiplication table for 2 number:
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2 * 10 = 20