fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. try{
  13. int[] numberOfDaysEachMonth = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  14. System.out.println("Enter month > ");
  15. Scanner month = new Scanner(System.in);
  16. int userInputMonth =month.nextInt();
  17. if (userInputMonth > 0 && userInputMonth < 13) {
  18. System.out.println("Enter the day of month > ");
  19. //Scanner day = new Scanner(System.in);
  20. int userInputDay = month.nextInt();
  21. if (userInputDay > 0 && userInputDay < numberOfDaysEachMonth[userInputMonth - 1]) {
  22. System.out.println("Correct date.");
  23. } else {
  24. System.out.println("Wrong date.");
  25. }
  26. } else {
  27. System.out.println("Wrong month.");
  28. }
  29. }catch(Exception e){
  30. System.out.println(e);
  31. }
  32. }
  33. }
Success #stdin #stdout 0.16s 321344KB
stdin
5
2
stdout
Enter month > 
Enter the day of month > 
Correct date.