# Verifying of Month

• 11-02-2010, 03:29 AM
ŖàΫ ỏƒ Ңόρę
Verifying of Month
Hi

In the following code; I ask the user to input the month then the program should verify if the input is one of the 12 months or not, if not the program gives him 3 chances to input the right month other than the program will stop.

Code:

```System.out.print("Month = ");                 Month = scan.next();                                 String MonArr [] = {"Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec"};                 int j;                 for (j=0; j<2; j++){                         for(int i=0; i<MonArr.length ; i++){                                 if (Month.equals(MonArr[i])){                                         i = MonArr.length + 1;                                         j=3;                                 }                         }                         if(j<2){                         System.out.print("Month = ");                         Month = scan.next();                         }                                         }                 if (j==2){System.exit(0);}                                         System.out.print("Day = ");                 Day = scan.nextInt();```
The problem is:

When the user enters the wrong month 2 times then enters the right month correctly, the program stops !!
• 11-02-2010, 04:12 AM
Zack
It's because it's asking for the month at the end of the loop. Basically here's what you're doing:
Code:

```Ask for month Check month If false, ask for month Check month If false, ask for month End loop```

What you'll want to do is move the "Month=" part above your "i" for loop. So it's like this:
Code:

```Loop x3:   Ask for month   Check month```

See what I mean?
• 11-02-2010, 05:34 PM
tashimoto
Did you figure it out yet??