HomeJavaJava Program to Generate Multiplication Table

Java Program to Generate Multiplication Table

In this Java program, you’ll learn how to Generate a Multiplication Table using the Java programming language.  

How to Generate Multiplication Table in JAVA? 

Example 1: using for loop

RUN CODE SNIPPET
public class Main 

{ 

    public static void main(String[] args) { 

 

        int num = 10; 

        for(int i = 1; i <= 20; ++i) 

        { 

            System.out.printf("%d * %d = %d \n", num, i, num * i); 

        } 

    } 

}

OUTPUT 

10 * 1 = 10  

10 * 2 = 20  

10 * 3 = 30  

10 * 4 = 40  

10 * 5 = 50  

10 * 6 = 60  

10 * 7 = 70  

10 * 8 = 80  

10 * 9 = 90  

10 * 10 = 100  

10 * 11 = 110  

10 * 12 = 120  

10 * 13 = 130  

10 * 14 = 140  

10 * 15 = 150  

10 * 16 = 160  

10 * 17 = 170  

10 * 18 = 180  

10 * 19 = 190  

10 * 20 = 200

Example 2: using while loop 

RUN CODE SNIPPET
public class Main 

{ 

    public static void main(String[] args)  

    { 

        int num = 2, i = 1; 

        while(i <= 10) 

        { 

            System.out.printf("%d * %d = %d \n", num, i, num * i); 

            i++; 

        } 

    } 

}

OUTPUT 

2 * 1 = 2  

2 * 2 = 4  

2 * 3 = 6  

2 * 4 = 8  

2 * 5 = 10  

2 * 6 = 12  

2 * 7 = 14  

2 * 8 = 16  

2 * 9 = 18  

2 * 10 = 20

In the above program, the value of i is incremented inside the body of the loop. 

Share:

Leave a Reply

You May Also Like

Java is a popular programming language that is used to develop a wide range of applications. If you are a...
  • Java
  • March 6, 2023
Java is a programming language and computing platform that is used to create various types of applications. It is used...
  • Java
  • March 6, 2023
In this post, you’ll learn how to download and install JUnit in Eclipse so that you can use in your...
  • Java
  • October 9, 2022