Question: This program needs to prompt user to enter date in asingle line separated with space. Example: input like 10 21 2018 should be month =

 This program needs to prompt user to enter date in asingle

This program needs to prompt user to enter date in asingle line separated with space. Example: input like 10 21 2018 should be month = 10, date = 21, and year = 2018. But when non-integers are intered, the program crashes. Using hasNextInt() method, the program needs to skip non-integer, so the program does not crash.

System.out.println ("Enter the date:"); System.out.println ("For example, January 21, 1939, would be: 1 21 1939") if (scan.hasNextInt)) f months scan.nextInt else if (scan.hasNextInt ()) dayscan.nextInt ) else if (scan.hasNextInt ) year = scan. next Int(); else scan.close )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!