- 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**