Java Program to Print Multiplication Table of Number

  • Write a Java program to print multiplication table of a number.

Given a number N, we have to print the multiplication table of N till 10 terms using a loop. In this java program, we are using a for loop to print table but same logic can be implemented using while or do-while loop.

For loop will iterate 10 times and in every iteration it will print one line of multiplication table.

Java program to print multiplication table of a number

package com.tcc.java.programs;

import java.util.Scanner;

/**
 * Java Program to print multiplication table of a number
 */
public class PrintTable {

    public static void main(String[] args) {
        int i, num;
        Scanner scanner;
        scanner = new Scanner(System.in);
        // Take input from user
        System.out.println("Enter a Number");
        num = scanner.nextInt();

        System.out.format("Multiplication Table of \n", num);

        for (i = 1; i <= 10; i++) {
            System.out.format("%d X %d = %d\n", num, i, num * i);
        }
    }
}
Output
Enter a Number
5
Multiplication Table of 
5 X 1 = 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25
5 X 6 = 30
5 X 7 = 35
5 X 8 = 40
5 X 9 = 45
5 X 10 = 50

Recommended Posts
Java Program to Print Pascal Triangle
Java Program to Print Fibonacci Series with and without using Recursion
Java Program to Print Prime Numbers between 1 to 100
Java Program to Print Pyramid Pattern of Stars
Java Program to Print Right Triangle Star Pattern
Java Program to Print Multiplication Table Triangle Pattern
Java Program to Print Diamond Pattern of Star Character
Java program to Print Square Pattern of Star Character
Java Program to Print Inverted Pyramid Pattern of Stars
Java Program to Print Right Triangle Pattern of Natural Numbers
All Java Programs