In this program, we are going to see how we can print the multiplication table of any user given input number.
Logic
Printing multiplication table of any number is quite simple and an easy task. After taking input (num) from the user we have to start one loop from 1 to 10, and then inside the loop simply multiply num by current number “i” and print it.
Program
import java.util.Scanner; public class MultiplicationTable { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Take input from user System.out.println("Enter number to print table : "); int num = scanner.nextInt(); System.out.println("Table of " + num); for(int i = 1; i <= 10; i++) { System.out.println(num + " * " + i + " = " + (num * i)); } } }
Output
Enter number to print table : 2
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