Java Program To Print Multiplication Table For Any Number

Logic for some programs are very easy but there outputs are very awesome.

Here is the java program to print multiplication table for any number. This is very easy program in which we will take table number from user and print the multiplication table for that number.

We can use Scanner class to get  input from the user. First we will create object of the scanner class.

Scanner sc = new Scanner(System.in);

We can get int value by nextInt() method of Scanner class.

int tableNumber = sc.nextInt();

Now can use for loop to print the table.

for(int count = 1; count<=10; count++){
    System.out.println(tableNumber +" * " +count +" = " +(tableNumber*count));
}

Here is the complete Java Program To Print Multiplication Table For Any Number:

package com.company.infohax;

import java.util.Scanner;

/**
 * Created by Shivashish Singh on 05-02-2017.
 */
public class MultiplicationTable {
    public static void main(String[] args) {
        System.out.println("**********Multiplication Table**********");

        System.out.println("Enter the number for which you want print multiplication table.");

        Scanner sc = new Scanner(System.in);
        int tableNumber = sc.nextInt();

        System.out.println("Table for "+tableNumber +" is: ");

        for(int count = 1; count<=10; count++){
            System.out.println(tableNumber +" * " +count +" = " +(tableNumber*count));
        }
    }
}

Output:
multiplicationtable multiplicationtable1

Here are some link for the classes that we have used in this program you can read that docs to improve your knowledge on classes.

Scanner Class

Please share this article with your friend. Keep visiting infohax daily. I will explain 1 java program daily which will definitely improve your java skill.

If you have any doubt please mention in the comment box.

Reply

%d bloggers like this: