Java Program to Display Multiplication Tables of Given Number

This is a java program to display multiplication table of given number. For java program to display multiplication table of all numbers from 1 to 10, see this post: Program to display multiplication table of all numbers from 1 to 10

import java.util.Scanner;

public class Multiples{

public static void main(String[] args)
{
    int n, i;
    Scanner sc=new Scanner(System.in);
    System.out.printf("Enter the number:");
    n=sc.nextInt();
    for(i=1; i<=10; ++i)
        System.out.printf("%d * %d = %d \n", i, n, n*i);
}
}

Output:

Enter the number:5
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50

No comments:

Post a Comment