Compute Multiplication Table in Java

Exercise:

Write a Java Program to compute multiplication table for a number (1 through 10).

Click Here to View the Solution!
public class Table {
  
     public static void main(String[] args) {
  
         int number = 6;
         for(int i = 1; i <= 10; ++i)
         {
          System.out.printf("%d * %d = %d \n", number , i, number * i);
         }
     }
} 
Click Here to View the Output!
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 
Click Here to View the Explanation!
  • This program is used for creating a multiplication table of a number through the use of a for loop and then print the entire table.
  • A variable number is initialized that holds the value 6.
  • A for loop is used which is given a condition that will loop a total of 10 times. Each time incrementing the value and storing in the variable i. Initially, i = 1.
  • The printing format and the operator * is set inside printf() in such a way that each time an iteration occurs, number is multiplied to the value i and the result is displayed along with number and i as follows: 6 * 1 = 6 (First iteration).