In this tutorial you will learn about the Java Program to Generate Multiplication Table and its application with practical example.
Java Program to Generate Multiplication Table
In this tutorial, we will learn to create a Java program that will generate a Multiplication Table using Java programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:
- Operators in Java Programming.
- Basic Input and Output function in Java Programming.
- Basic Java programming.
- Conditional Statements in Java programming.
- Arithmetic operations in Java Programming.
Program that will generate the multiplication table:-
In today’s program, we will take input in number format. Secondly, we will generate a Multiplication Table with the help of a small program. The numbers are the most useful terminology in any programming language. For number/arithmetic manipulation in Java programming, there are many predefined functions available.
With the help of this program, we can take input and will Generate the Multiplication Table.
Algorithm:-
1 2 3 4 5 6 7 |
1. Declaring the variables for the program. 2. Taking the input numbers from the user in number format. 3. Generating the table and storing it in a variable. 4. End program. |
Program:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import java.util.Scanner; //Importing the scanner class through the package public class TBL//Main class of the program. { //Main function of the program. public static void main(String args[]) { //Declaring the variables for the program. int i,no; //Taking the input number from the user. Scanner sc = new Scanner(System.in); System.out.print("Enter number: "); //reading a number whose table is to be print no =sc.nextInt(); //loop start execution form and execute until the condition i<=10 becomes false //Generating the table from 1 to 10 for( i=1; i <= 10; i++) { //prints table of the entered number System.out.println(no +" * "+i+" = "+ no*i); } } } |
Output:-
In the above program, we have first initialized the required variable.
- no = it will hold the input number value from the user.
- i = it will hold the integer value.
Taking input numbers from the user.
Calculating the table of given numbers using a for loop.