Print table program in Java

In this section you will learn how to print a table of given number. Here we will apply multiplication operation to print the table. We will take the input from user.

What is scanner function?

Scanner function is use to take the input from user in java.

How program will work?

Program of print table in Java


	import java.util.Scanner;

	class Table
	{
		public static void main(String arg[])
		{
			int i, n, sum;
			Scanner sc = new Scanner(System.in);
			System.out.println("ENTER A NUMBER TO PRINT A TABLE:- ");
			n = sc.nextInt();
			for(i=1; i<=10; i++)
			{
				sum=i*n;
				System.out.println(sum);
			}
		}
	}

Output:


	ENTER A NUMBER:- 5
	5
	10
	15
	20
	25
	30
	35
	40
	45
	50

Advertisment

Post Your Comment