I tried to create an if statement inside my code to print a message if the user entered a wrong type of input rather than showing the "InputMismatchException" message by the compiler.
import java.util.*;
public class Pr8 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//Prompt the user for how many integers are going to be entered
System.out.print("*Please write how many numbers are going to be entered: ");
int a = scan.nextInt();
int[] n = new int[a];
if(a >= 0)
for(int i = 0; i < a; i++) {
System.out.print("*Please enter an enteger: ");
n[i] = scan.nextInt();
}//for
else
System.out.print("*Sorry your entery was not correct. Please enter digits only. ");
}//main
}//Pr8
check for
scan.hasNextInt()
, this will work for you.