Question #254147

Write a Java program that prompts the user to enter the number they wish
to see the multiplication table of. In addition, the program should prompt
the user to enter the length of multiplication table (i.e. counter) and
displays the table on the screen.

Expert's answer

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Number: ");
        int number = in.nextInt();
        System.out.print("Length: ");
        int length = in.nextInt();
        for (int i = 1; i <= length; i++) {
            System.out.println(number + " * " + i + " = " + number * i);
        }
    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS