PROGRAM 3 – Times tables
You must write a small application in JAVA that will read in a positive integer and then display the times tables for that number, from 1 to 12.
Your program must
1. Read in the integer as input.
2. Calculate and display the complete times tables up to 12 for that integer.
3. If a zero or any number less is entered, an error message must be displayed and the user must be allowed to input another value.
import java.util.*;
class App {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int n = -1;
while (n < 1) {
System.out.print("Enter the integer number: ");
n = keyboard.nextInt();
if (n < 1) {
System.out.println("Wrong the integer number! Try again. ");
}
}
for (int i = 1; i <= 12; ++i) {
System.out.println(n + " * " + i + " = " + n * i);
}
keyboard.close();
}
}
Comments
Leave a comment