Table of Contents
In this article, we will discuss the concept of Java code to Display multiplication table of a number in given range
In this program, we are going to learn how to generate a multiplication table using several ways in Java language.
This is done using for loop , while loop , do-while loop and method in Java language
In this program, we will display the multiplication table of a number in given range using a for loop in Java language
Program 1
import java.util.Scanner; public class Multiplication_Table{ 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 result
Enter the number: 9 Enter the range 11 9x`1=9 9x2=18 9x`3=27 9x4=36 9x`5=45 9x6=54 9x`7=63 9x8=72 9x`9=81 9x10=90 9x`11=99
In this program, we will display the multiplication table of a number in given range using a while loop in Java language
Program 2
import java.util.Scanner; public class MultiplicationTableWhile{ 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 result
Enter the number 5 Enter the range 9 5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
In this program, we will display the multiplication table of a number in given range using a do-while loop in Java language
Program 3
import java.util.Scanner; public class MultiplicationTableDoWhile{ 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 result
Enter the number 6 Enter the range 9 6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=35 6x7=40 6x8=45 6x9=54 6x10=60
In this program, we will display the multiplication table of a number in given range using a method in Java language
Program 4
//Java program to print multipication tabe //using method import java.util.Scanner; class MultipicationTableMethod{ public static void main(String args[]){ int num,range; Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the any number: "); num=scan.nextInt();//get input from the user for num System.out.print("Enter the range: "); range=scan.nextInt(); mulTable(num,range); } public static void mulTable(int num,int range){ 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 result
Enter the any number:7 Enter the range: 9 7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 7x8=56 7x9=63
Suggested post
do-while loop 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
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.