Multiplication Table in Java

Print the multiplication table of a given number.

BeginnerModule 3: Loop ProgramsExample 19 of 25
multiplication-table.java
1import java.util.Scanner;
2
3public class Main {
4 public static void main(String[] args) {
5 Scanner sc = new Scanner(System.in);
6 System.out.print("Enter a number: ");
7 int n = sc.nextInt();
8
9 for (int i = 1; i <= 10; i++) {
10 System.out.println(n + " x " + i + " = " + (n * i));
11 }
12 sc.close();
13 }
14}

Output

Enter a number: 5
5 x 1 = 5
5 x 2 = 10
...
5 x 10 = 50

What's going on

We loop i from 1 to 10 and print n × i each time.