multiplication table
Table of Contents
In this article, we will discuss the concept of Program to Display multiplication table in Java.
In this program, we are going to learn how to generate a multiplication table.
This is done using for loop , while loop , do-while loop , method and recursion in Java language
Program 1
In this program, we will display the multiplication table using a for loop in Java language
//Java program to print multipication tabe //using for loop import java.util.Scanner; class Multipication_tabe{ public static void main(String args[]){ int num, i; Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); num=scan.nextInt();//get input from the user for num for(i=1; i<=12; i++){ System.out.println(num+" * "+i+" = "+num*i); } } }
When the above code is executed, it produces the following result
In this program, we can display the multiplication table using a while loop in Java anguage. here, the while loop is functioning until the condition of the while loop is true
Program 2
//Java program to print multipication tabe //using while loop import java.util.Scanner; class Multipication_tabe1{ public static void main(String args[]){ int num, i,j; Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); num=scan.nextInt();//get input from the user for num i=1; while(i<=12){ System.out.println(num+" * "+i+" = "+num*i); i++; } } }
When the above code is executed, it produces the following result
In this program, we will display the multiplication table using a do-while loop in Java language. here, the while loop is functioning until the condition of the while loop is true
Program 3
//Java program to print multipication tabe //using do-while loop import java.util.Scanner; class Multipication_tabe2{ public static void main(String args[]){ int num, i,j; Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); num=scan.nextInt();//get input from the user for num i=1; do{ System.out.println(num+" * "+i+" = "+num*i); i++; }while(i<=12); } }
When the above code is executed, it produces the following result
In this program, we will display the multiplication table using a method in Java language.
Program 4
//Java program to print multipication tabe //using method import java.util.Scanner; class Multipication_table_Method{ public static void main(String args[]){ int num, i,j; Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); num=scan.nextInt();//get input from the user for num mulTable(num); } public static void mulTable(int num){//method definision int i; for(i=1; i<=12; i++){ System.out.println(num+" * "+i+" = "+num*i); } } }
When the above code is executed, it produces the following result
In this program, we will display the multiplication table using a recursion in Java language.
Program 5
Recursion is a technique in Java programming where a method calls itself recursively. This technique is used to substitution the loops to execute the same code multiple time
//Java program to print multipication tabe //using recursive method import java.util.Scanner; class Multipication_table_Recursion{ public static void main(String args[]){ Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); int num=scan.nextInt();//get input from the user for num mulTable(num,1); } public static void mulTable(int num,int count){ if(count<=12){ System.out.println(num+" * "+count+" = "+num*count); mulTable(num,++count); //call the function inside the same function } } }
When the above code is executed, it produces the following result
Suggested post
do-while loop in Java language
Similar post
Program to Display multiplication table in Java
Program to Display multiplication table in C
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.