Coding Practice

Write a Java program to print multiplication table of any number

Print multiplication table of any number
Sample Output
Print multiplication table of any number.

Enter a number: 5
Enter limit: 10
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
Java-Source Code
//package loopinjava;
import java.util.Scanner;

public class Main9 {

    public static void main(String[] args) {
        
        int n, number, limit;
        
        Scanner input = new Scanner(System.in);
        
        System.out.println("Print multiplication table of any number.\n");
        
        System.out.print("Enter a number: ");
        number = input.nextInt();

        System.out.print("Enter limit: ");
        limit = input.nextInt();

        n = number;
        for(n = 1; n <= limit; n++){
            
            System.out.println(number + " * " + n + " = " + (number * n));
        }
    }
}
Sample Output
Print multiplication table of any number.

Enter a number: 10
Enter limit: 5
10 * 1 = 10
10 * 2 = 20
10 * 3 = 30
10 * 4 = 40
10 * 5 = 50

No comments:

Post a Comment

Change Theme
X