1. The InputMismatchException.
Write a program that prompts the user to read an integer and displays whether the number is even or odd. If you enter an invalid integer (for example, 2.5 is not a valid integer) your program should say so. Note, you will need the following import statement:
import java.util.InputMismatchException;
I have started the code but am struggling to get things moving. This is my first programming class so apologize for noobish errors =(
import java.util.InputMismatchException;
import java.util.Scanner;
public class Lab14 {
public static int prime;
public static void main(String[] args){
Scanner input = new Scanner(System.in);
while (true) {
System.out.print("Please enter a number: ");
if(input.hasNextInt()){
int prime = input.nextInt();
break;
}
else{
System.out.println("\nNot a number or an integer!\n");
input.next();
}
}