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.
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
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
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
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:
This multiplication table is shown in the form of the table
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:
This multiplication table is shown in the form of the table
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:
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
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…