1. Engineering
  2. Computer Science
  3. how can i validate the input of this program so...

Question: how can i validate the input of this program so...

Question details

How can I validate the input of this program so that it prints an error message when the user enters a non-integer? import java.util.Scanner; /** * @author */ public class Project5_1 { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scan = new Scanner (System.in); //Creates a new scanner. System.out.println ("Please enter a year after 1581:"); Integer num = scan.nextInt(); System.out.println ("You did not enter a valid year before 1581. " + "Please enter a year after 1581."); if (num >= 1582) { if (num % 4 == 0 && num % 100 != 0 || num % 400 == 0) System.out.println (num + " is a leap year."); else System.out.println (num + " is not a leap year."); } else System.out.println ("You did not enter a valid year before 1581." + " Please enter a year after 1581."); }} Thank you

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution