Java Program to Display Multiplication Table

You are Here:

Using for Loop

In the following example, we will create and display the Multiplication Table for the given number (9) using for loop

Example

Java Compiler
public class myClass { public static void main(String[] args) { int table = 9; int length = 10; int i = 1; System.out.print("Multiplication table: " +table); for(i=1; i<=length; i++) System.out.format("\n%2d * %d = %d", i, table, i * table); } }

Output

Multiplication table: 9 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 10 * 9 = 90

Using while Loop

In the following example, we will create and display the Multiplication Table for the given number (9) using while loop

Example

Java Compiler
public class myClass { public static void main(String[] args) { int table = 9; int length = 10; int i = 1; System.out.print("Multiplication table: " +table); while(i <= length) { System.out.format("\n%2d * %d = %d", i, table, i * table); i++; } } }

Output

Multiplication table: 9 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 10 * 9 = 90

Using do while Loop

In the following example, we will create and display the Multiplication Table for the given number (9) using do while loop

Example

Java Compiler
public class myClass { public static void main(String[] args) { int table = 9; int length = 10; int i = 1; System.out.print("Multiplication table: " +table); do { System.out.format("\n%2d * %d = %d", i, table, i * table); i++; }while(i <= length); } }

Output

Multiplication table: 9 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 10 * 9 = 90

Display Customized Table

In the following example, we will display the table according to the given table number and table length.

Example

Java Compiler
import java.util.Scanner; public class myClass { public static void main(String[] args) { int table, length, i; Scanner reader = new Scanner(System.in); System.out.print("Enter the table number: "); table = reader.nextInt(); System.out.print("Enter the length: "); length = reader.nextInt(); System.out.print("\nMultiplication table: " +table); for(i=1; i<=length; i++) System.out.format("\n%2d * %d = %d", i, table, i * table); } }

Output

Enter the table number: 5 Enter the length: 10 Multiplication table: 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

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on Java with examples for quick and easy learning.

We are working to cover every Single Concept in Java.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author