do{
    try{
        System.out.println("Please enter the publication year :");
        year=keyboard.nextInt();
        doneYear=true;
    } catch(InputMismatchException e) {
        System.out.println("Please enter a number.");
    }
} while(!doneYear);
This doesn't work. It loops infinitely once I hit the first exception.
 
    