Java Program to Print Multiplication Table of a Number

In this post we will go through the basic java program to print table of a number :

Input :

Enter number : 5

Output :

Multiplication table of 5

5 * 1 = 5

5 * 2 = 10

5 * 3 = 15

5 * 4 = 20

5 * 5 = 25

5 * 6 = 30

5 * 7 = 35

5 * 8 = 40

5 * 9 = 45

5 * 10 = 50

Approach 1: using for loop :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import java.util.Scanner;
public class MultiplicationTable
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.print("Enter number :");
int num=s.nextInt();
System.out.println("Multiplication table of "+num);
for(int i=1; i <= 10; i++)
{
System.out.println(num+" * "+i+" = "+num*i);
}
}
}
import java.util.Scanner; public class MultiplicationTable { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.print("Enter number :"); int num=s.nextInt(); System.out.println("Multiplication table of "+num); for(int i=1; i <= 10; i++) { System.out.println(num+" * "+i+" = "+num*i); } } }
import java.util.Scanner;
public class MultiplicationTable 
{
    public static void main(String[] args) 
    {
        Scanner s = new Scanner(System.in);
    System.out.print("Enter number :");        
    int num=s.nextInt();
    System.out.println("Multiplication table of "+num);
        for(int i=1; i <= 10; i++)
        {
            System.out.println(num+" * "+i+" = "+num*i);
        }
    }
}

Approach 2: using While loop :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter number :");
int num=s.nextInt();
System.out.println("Multiplication table of "+num);
int i = 1;
while(i<=10) {
System.out.println(num+" * "+i+" = "+num*i);
i++;
}
}
}
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.print("Enter number :"); int num=s.nextInt(); System.out.println("Multiplication table of "+num); int i = 1; while(i<=10) { System.out.println(num+" * "+i+" = "+num*i); i++; } } }
import java.util.Scanner;
public class Main {
    public static void main(String[] args) { 
        Scanner s = new Scanner(System.in); 
        System.out.print("Enter number :");
         int num=s.nextInt();
       System.out.println("Multiplication table of "+num); 
       int i = 1;
      while(i<=10) { 
      System.out.println(num+" * "+i+" = "+num*i);
      i++;
      }
   }
}

More java programs:

Java Program to Get Input from User

Addition of two numbers in java

Java Program to Reverse a Number

Java Program to Check a Number is Palindrome or Not

 

 

Leave a Comment

%d bloggers like this:
Python4U
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.