Java Program to print table of any number using while loop


In this program, You will learn how to print a table of any number using a while loop in java.


Table is: 14 28 42 56 70 84 98 112 126 140

Example: How to print a table of any number using a while loop in java

import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        int num;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number:");
        num = sc.nextInt();

        int i = 1;

        while (i <= 10) {
            System.out.println(i * num);
            i++;
        }

    }

}

Output:

Enter a number:5
5
10
15
20
25
30
35
40
45
50