w3resource
Java Programming Exercies

Java Exercises: Print multiplication table of a number upto 10

Java Basic: Exercise-7 with Solution

Write a Java program that takes a number as input and prints its multiplication table upto 10.

Test Data:
Input a number: 8

Pictorial Presentation:

Java: Print multiplication table of a number upto 10

Sample Solution:

Java Code:

import java.util.Scanner;
 
public class Exercise7 {
 
 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
   
  System.out.print("Input a number: ");
  int num1 = in.nextInt();
   
  for (int i=0; i< 10; i++){
   System.out.println(num1 + " x " + (i+1) + " = " + 
     (num1 * (i+1)));
  }
 }
}

Sample Output:

Input a number: 8                                                                                             
8 x 1 = 8                                                                                                     
8 x 2 = 16                                                                                                    
8 x 3 = 24                                                                                                    
8 x 4 = 32                                                                                                    
8 x 5 = 40                                                                                                    
8 x 6 = 48                                                                                                    
8 x 7 = 56                                                                                                    
8 x 8 = 64                                                                                                    
8 x 9 = 72                                                                                                    
8 x 10 = 80 

Flowchart:

Flowchart: Java exercises: Print multiplication table of a number upto 10.

Sample Solution:

Java Code:

import java.util.Scanner;

public class Main {

 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  System.out.println("Input the Number: ");
  int n = in .nextInt();
  for (int i = 1; i <= 10; i++) {
   System.out.println(n + "*" + i + " = " + (n * i));
  }
 }
}

Sample Output:

Input the Number: 
 6
6*1 = 6
6*2 = 12
6*3 = 18
6*4 = 24
6*5 = 30
6*6 = 36
6*7 = 42
6*8 = 48
6*9 = 54
6*10 = 60

Flowchart:

Flowchart: Java exercises: Print multiplication table of a number upto 10.

Java Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers.
Next: Write a Java program to display the specified pattern.

What is the difficulty level of this exercise?