Table

Java program to display multiplication table

Java program to display multiplication table

In this tutorial, we will discuss Java program to display multiplication table using loops

We will learn how to create a multiplication table using loops. we can create multiplication table using for loop, while loop and do – while loop in C language.

Create multiplication table using for loop

Program 1

we can create a multiplication table using for loop in Java language

import java.util.Scanner;
public class Multiplication_Table{
public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
int num=0;
System.out.println("Enter the number: ");
num=sc.nextInt();
for(int i=1; i<=10; i++){
System.out.println(num+"x"+i+"="+num*i);

            }
        }

    }

When the above code is executed, it produces the following results:

Enter the number:
10
10x1=10
10x2=20
10x3=30
10x4=40
10x5=50
10x6=60
10x7=70
10x8=80
10x9=90
10x10=100

This multiplication is shown and explained using “x” mark

Program 2

In this program, the user can provide a needed range according to their preference and produced their all multiplication table according to the value provided

import java.util.Scanner;
public class Multiplication_Table1{
public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
int num,range;
System.out.println("Enter the number: ");
num=sc.nextInt();
System.out.println("Enter the range: ");
range=sc.nextInt();
for(int i=1; i<=range; i++){
System.out.println(num+"x"+i+"="+num*i);

            }
        }

    }

When the above code is executed, it produces the following results:

Enter the number:
15
Enetr the range:
12
15x1=15
15x2=30
15x3=45
15x4=60
15x5=75
15x6=90
15x7=105
15x8=120
15x9=135
15x10=150
15x11=165
15x12=180

 

Create multiplication table using while loop

we can create a multiplication table using while loop in Java language

import java.util.Scanner;
public class Multiplication_Table2{
public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
int num;
System.out.println("Enter the number: ");
num=sc.nextInt();
int i=1;
while( i<=10;){
System.out.println(num+"x"+i+"="+num*i);
 i++;

            }
        }

    }

When the above code is executed, it produces the following results:

Enter the number:
12
12*1=12
12*2=24
12*3=36
12*4=48
12*5=60
12*6=72
12*7=84
12*8=96
12*9=108
12*10=120

 

Program 2

In this program, the user can provide a needed range according to their preference and produced their all multiplication table according to the value provided

import java.util.Scanner;
public class Multiplication_Table3{
public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
int num,range;
System.out.println("Enter the number: ");
num=sc.nextInt();
System.out.println("Enter the range: ");
range=sc.nextInt();
int i=1;
while(i<=range){
System.out.println(num+"x"+i+"="+num*i);
 i++;

            }
        }

    }

When the above code is executed, it produces the following results:

Enter the number:
12
Enter the range
12
12X1=12
12X2=24
12X3=36
12X4=48
12X5=60
12X6=72
12X7=84
12X8=96
12X9=108
12X10=120
12X11=132
12X12=144

This multiplication is shown and explained using “x” mark

Create multiplication table using do-while loop

Program 1

we can create a multiplication table using the do-while loop in Java language

import java.util.Scanner;
public class Multiplication_Table4{
public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
int num;
System.out.println("Enter the number: ");
num=sc.nextInt();
int i=1;
do{
System.out.println(num+"x"+i+"="+num*i);
 i++;
}while( i<=12);


        }

    }

When the above code is executed, it produces the following results:

Enter the number:
15
15X1=15
15X2=30
15X3=45
15X4=60
15X5=75
15X6=90
15X7=105
15X8=120
15X9=135
15X10=150
15X11=165
15X12=180

Program 2

In this program, the user can provide a needed range according to their preference and produced their all multiplication table according to the value provided

import java.util.Scanner;
public class Multiplication_Table5{
public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
int num,range;
System.out.println("Enter the number: ");
num=sc.nextInt();
System.out.println("Enter the range: ");
range=sc.nextInt();
int i=1;
do{
System.out.println(num+"x"+i+"="+num*i);
 i++;
}
while(i<=range);

        }

    }

When the above code is executed, it produces the following results:

Enter the number:
12
Enter the range:
11
12x1=12
12x2=24
12x3=36
12x4=48
12x5=60
12x6=72
12x7=84
12x8=96
12x9=108
12x10=120
12x11=132

 

Another form of the multiplication table

Multiplication table using nested for loop

public class Multiplication_Table6{
public static void main (String args[]){
System.out.print("Multiplication table\n");
for(int i=1; i<=10; i++){ 
    for(int j=1; j<=10; j++){
     System.out.print(i*j+"\t");
            }
            System.out.println();

        }
    }
}

When the above code is executed, it produces the following results:

Multiplication table

This multiplication table is shown in the form of the table

Multiplication table using nested while loop

public class Multiplication_Table7{
public static void main (String args[]){
System.out.print("Multiplication table\n");
int i=1;
while(i<=10){ 
int j=1; 
    while(j<=10){
     System.out.print(i*j+"\t");
     j++;
            }
            i++;
            System.out.println();

        }
         
    }
}

When the above code is executed, it produces the following results:

Multiplication Table

This multiplication table is shown in the form of the table

 

Multiplication table using nested do- while loop

public class Multiplication_Table8{
public static void main (String args[]){
System.out.print("Multiplication table\n");
int i=1;
do{
int j=1; 
do{
System.out.print(i*j+"\t");
     j++;
}while(j<=10);
i++;
System.out.println();

 }while(i<=10);
            

        }
         
}

When the above code is executed, it produces the following results:

Multiplication Table

This multiplication table is shown in the form of the table

Similar post

Multiplication table program in Java

Multiplication table program in Java using array

Multiplication table program in C

Multiplication table program in C++

Multiplication table program in Python

 

Suggested for you

For loop in Java language

For loop in C++ language

For loop in C language

For loop in Python language

 

While loop in Java language

While loop in C language

While loop in C++ language

While loop in Python language

 

Do-while loop in Java language

Do-while loop in C language

Do-while loop in C++ language

C program to create multiplication table
Cpp program to multiplication table
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

2 days ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

5 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago