In this tutorial we will print multiplication table of a entered number using for loop.
Java code is implemented below
/*
printing a multiplication table in java using scanner class
*/
import java.util.Scanner;
public class Table {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a Number to get its multiplication table: ");
int n = scanner.nextInt(); // Taking input from user
scanner.close();
/*
* using for loop we will print table like n X i = result
*/
for (int i = 1; i <= 10; i++) {
int result = n * i;
System.out.println(n + " X " + i + " = " + result);
}
}
}
Output:
Enter a Number to get its multiplication table: 13
13 X 1 = 13
13 X 2 = 26
13 X 3 = 39
13 X 4 = 52
13 X 5 = 65
13 X 6 = 78
13 X 7 = 91
13 X 8 = 104
13 X 9 = 117
13 X 10 = 130
13 X 1 = 13
13 X 2 = 26
13 X 3 = 39
13 X 4 = 52
13 X 5 = 65
13 X 6 = 78
13 X 7 = 91
13 X 8 = 104
13 X 9 = 117
13 X 10 = 130