Java Program to Print Multiplication Table for Any Number

Given a number n as input, we need to print its table, where N>0.

**Example**

Input 1 :- N = 7Output :- 7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49 7 * 8 = 56 7 * 9 = 63 7 * 10 = 70

**Two ways are shown to Print Multiplication Table for any Number:**

- Using for loop for printing the multiplication table upto 10.
- Using while loop for printing the multiplication table upto the given range.

**Method 1: Generating Multiplication Table using for loop upto 10**

## Java

`// Java Program to print the multiplication table of the ` `// number N. ` ` ` `class` `GFG { ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `// number n for which we have to print the ` ` ` `// multiplication table. ` ` ` `int` `N = ` `7` `; ` ` ` ` ` `// looping from 1 to 10 to print the multiplication ` ` ` `// table of the number. ` ` ` `// using for loop ` ` ` `for` `(` `int` `i = ` `1` `; i <= ` `10` `; i++) { ` ` ` `// printing the N*i,ie ith multiple of N. ` ` ` `System.out.println(N + ` `" * "` `+ i + ` `" = "` ` ` `+ N * i); ` ` ` `} ` ` ` `} ` `}` |

*chevron_right*

*filter_none*

**Output**

7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49 7 * 8 = 56 7 * 9 = 63 7 * 10 = 70

**Method 2:- Generating Multiplication Table using while loop upto any given range**

## Java

`// Java Program to print the multiplication table of ` `// number N using while loop ` ` ` `class` `GFG { ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `// number n for which we have to print the ` ` ` `// multiplication table. ` ` ` `int` `N = ` `7` `; ` ` ` ` ` `int` `range = ` `18` `; ` ` ` ` ` `// looping from 1 to range to print the ` ` ` `// multiplication table of the number. ` ` ` `int` `i = ` `1` `; ` ` ` ` ` `// using while loop ` ` ` `while` `(i <= range) { ` ` ` ` ` `// printing the N*i,ie ith multiple of N. ` ` ` `System.out.println(N + ` `" * "` `+ i + ` `" = "` ` ` `+ N * i); ` ` ` `i++; ` ` ` `} ` ` ` `} ` `}` |

*chevron_right*

*filter_none*

**Output**

7 * 1 = 7 7 * 2 = 14 7 * 3 = 21 7 * 4 = 28 7 * 5 = 35 7 * 6 = 42 7 * 7 = 49 7 * 8 = 56 7 * 9 = 63 7 * 10 = 70 7 * 11 = 77 7 * 12 = 84 7 * 13 = 91 7 * 14 = 98 7 * 15 = 105 7 * 16 = 112 7 * 17 = 119 7 * 18 = 126

Attention reader! Don’t stop learning now. Get hold of all the important **Java Foundation** and Collections concepts with the **Fundamentals of Java and Java Collections Course** at a student-friendly price and become industry ready.