Make A Multiplication Table in Java with a specific range
In this post, I’m going to write a java program where the user can give the input which is going to be multiplied and user can also give the range as an input. That means create a multiplication table in Java.
Create multiplication table in Java with a specific range
import java.util.Scanner; public class codespeedy { public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("Enter the number Which is being to be multiplied"); int a=scan.nextInt(); System.out.println("Enter the multiplication range"); int b=scan.nextInt(); System.out.println("The multiplication table of:"+a+" is given below"); for(int i=1;i<=b;i++) { System.out.println(a+" x "+i+" = "+(a*i)); } } }
Input and Output:
Java Program To Make Fibonacci Series With Explanation
Enter the number Which is being to be multiplied 15 Enter the multiplication range 14 The multiplication table of:15 is given below 15 x 1 = 15 15 x 2 = 30 15 x 3 = 45 15 x 4 = 60 15 x 5 = 75 15 x 6 = 90 15 x 7 = 105 15 x 8 = 120 15 x 9 = 135 15 x 10 = 150 15 x 11 = 165 15 x 12 = 180 15 x 13 = 195 15 x 14 = 210
the output will look like this.
Explanation of this program: Make multiplication table in Java
We have taken two inputs from the user here…. one is stored in a and another one is stored in b by scanner.
variable “a” is used here to let the program know which number we are going to be multiplied in a given range and “b” is used to give the value of range.
For example, I have taken 15 as a and 14 as b.
so when we run the program.
a=15
and b=14
now look at this below loop carefully:
for(int i=1;i<=b;i++)
{
System.out.println(a+” x “+i+” = “+(a*i));
}
we have taken a variable i and initialized the loop by setting up the value of i=1
so thus the loop will continue until we reach the ending point i,e is our range, given by the user at runtime. System.out.println(a+” x “+i+” = “+(a*i));
for this line, lets see what happens in the very first loop.
value of a will be printed first that is 15
then x sign will be printed and it will look like 15 x
Thereafter the value of “i” will be printed. and it will look like 15 x 1=
after the equal sign, the product of a and b will be printed
and finally, it will look like 15 x 1 = 15
and the loop will be executed until we reach the final range.
Happy coding 🙂
Leave a Reply