Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C program to Generate multiplication table

Program to Display multiplication table in Java

Posted on October 19, 2020October 23, 2020

Table of Contents

  • Program to display multiplication table in Java
    • Code to print multiplication table in Java
      • Java code to print multiplication table using for loop
      • Java code to print multiplication table using while loop
      • Java code to print multiplication table using do-while loop
      • Java code to print multiplication table using method
      • Java code to print multiplication table using recursion

Program to display multiplication table in Java

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

Code to print multiplication table in Java

Java code to print multiplication table using for loop

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

Program to Display multiplication table in Java
Print multiplication table

 

  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanner class and store to the variable num
  • Create a for loop of i from 1 to 12 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table using System.out.print() function.

Java code to print multiplication table using while loop

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

Program to Display multiplication table in Java
print multiplication table
  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanner class and store to the variable num
  • Create a while loop of i from 1 to 12 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table using System.out.print() function.

Java code to print multiplication table using do-while loop

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

Program to Display multiplication table in Java
print multiplication table

 

  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanner class and store to the variable num
  • Create a do-while loop of i from 1 to 12 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table using System.out.print() function.

 

Java code to print multiplication table using method

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

Program to Display multiplication table in Java
Print multiplication table
  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanner class and store to the variable num
  • define a method named as mulTable(int num) for print multiplication table
  • Call the method to display multiplication table

Java code to print multiplication table using recursion

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

Program to Display multiplication table in Java
Multiplication table in Java

 

Suggested post

for loop in Java language

while loop in Java language

do-while loop in Java language

method in Java language

Operator in Java language

Data type in Java language

 

Similar post

Program to Display multiplication table in Java

Program to Display multiplication table in C

Program to Display multiplication table in C++

Program to Display multiplication table in Python

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes