My program prompts the user to enter an Integer. 
For example:
int numbers = keyboard.nextInt(); 
So, when they enter a letter, my Java program immediately crashes.
How can I display an error message instead of having Java crashing the program?
My program prompts the user to enter an Integer. 
For example:
int numbers = keyboard.nextInt(); 
So, when they enter a letter, my Java program immediately crashes.
How can I display an error message instead of having Java crashing the program?
By using a try-catch statement:
Scanner scan = new Scanner(System.in);
boolean validInput = false;
int val = 0;
while(!validInput) {
    try {
        val = scan.nextInt();
        validInput = true;
    } catch(InputMismatchException e) {
        System.out.println("Please enter an integer!");
        scan.next();
    }
}
System.out.println("You entered: " + val);
 
    
    This is a situation where exception comes in handy.
An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore, these exceptions are to be handled.
An exception can occur for many different reasons. Following are some scenarios where an exception occurs.
A user has entered an invalid data.
A file that needs to be opened cannot be found.
A network connection has been lost in the middle of communications or the JVM has run out of memory.
So in your case surround the code which might cause the error with try block..
when the use will input the wrong type instead of terminating the you can decide what to display on screen.
try{
//code that can produce error i.e. input statement
}catch(Exception e){
System.out.println("Enter Integer");
}
 
    
    You can do so by taking an input as string and checking whether it's a number by regex, e.g.:
public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(System.in);
    String input = scanner.next();
    if(!input.matches("[\\-]?[0-9]+")){
        System.out.println("Wrong input");
    }
}
