Multiplication Table

Print the multiplication table of a given number.

JavaBeginner
Java
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int n = sc.nextInt();

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

Output

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

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