Multiplication Table in Java Program using For loop
ADVERTISEMENTS
Multiplication table in java program using for loop. In this article, you will learn how to print the multiplication table in java program using for loop.
Source Code
// Multiplication Table in Java Program using For loop
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x, r, i;
// x - To store the input number
// r - To store the multiplication range
System.out.println ("----Enter the input number is::---\n");
x = in.nextInt();
System.out.println ("\n----Enter the range number is::----\n");
r = in.nextInt();
System.out.println ("\n\n------The above multiplication table--------\n\n");
for (i = 1; i <= r; i++) {
System.out.print (x + " * " + i + " = " + (x * i) + "\n");
}
}
}
Output
----Enter the input number is::---
13
----Enter the range number is::----
12
------The above multiplication table--------
13 * 1 = 13
13 * 2 = 26
13 * 3 = 39
13 * 4 = 52
13 * 5 = 65
13 * 6 = 78
13 * 7 = 91
13 * 8 = 104
13 * 9 = 117
13 * 10 = 130
13 * 11 = 143
13 * 12 = 156