Java program to print table for given number
Following program shows you how to print table for given number.
In this program we get number from user and print that number table using for loop
import java.util.Scanner;
public class BasicMath4 {
public static void main(String[] args) {
System.out.println("Enter the number:");
Scanner in = new Scanner(System.in);
int input = in.nextInt();
for (int i = 1; i <= 10; i++) {
System.out.println(input + " * " + i + " = " + input * i);
}
}
}
Output:
Enter the number:
3
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30