"else" without "if" error.....
I can not figure out what is wrong with this. Could someone please have a look and help me out. I know this is not the most efficient way to do this, but I just need to find my errors. Any help is extremely appreciated.
Here's the code:
Code:
import javax.swing.*; //make swing available
public class LeapYear
{
public static void main (String args[]) //main method
{ //start the main method
int montIn, yearIn, secondCheck, finalCheck;
boolean isLeapYear;
monthIn=JOptionPane.showInputDialog("Enter the month as an integer:"); //ask for month input
if (monthIn==0) //exit the program if the month is 0
System.exit(0);
yearIn=JOptionPane.showInputDialog("Enter the Year (4 digits):"); //ask for year input
checkLeapYear=yearIn%4; //check to see if year is a leap year
if (checkLeapYear==0) //The year is possibly a leap year; do some more checking
secondCheck=yearIn%100; //is it divisible by 100?
if (secondCheck==0) //is divisible by 100, do some more checking
finalCheck=yearIn%400; //is it divisible by 400?
if (finalcheck==0) //is divisible by 400, passes test!
isLeapYear=True; //the year is a leap year
else //year is not divisible by 100
isLeapYear=False;
else //The Year is NOT a leap year (not divisible by 4)
isLeapYear=False;
{ //start new method
if (isLeapYear=="True") //The Year is a leap year
switch (monthInt)
{
case 1:
JOptionPane.showMessageDialog(null, "There are 31 days in January of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 2:
JOptionPane.showMessageDialog(null, "There are 29 days in February of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 3:
JOptionPane.showMessageDialog(null, "There are 31 days in March of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 4:
JOptionPane.showMessageDialog(null, "There are 30 days in April of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 5:
JOptionPane.showMessageDialog(null, "There are 31 days in May of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 6:
JOptionPane.showMessageDialog(null, "There are 30 days in June of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 7:
JOptionPane.showMessageDialog(null, "There are 31 days in July of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 8:
JOptionPane.showMessageDialog(null, "There are 31 days in August of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 9:
JOptionPane.showMessageDialog(null, "There are 30 days in September of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 10:
JOptionPane.showMessageDialog(null, "There are 31 days in October of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 11:
JOptionPane.showMessageDialog(null, "There are 30 days in November of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 12:
JOptionPane.showMessageDialog(null, "There are 31 days in December of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
}
else //is not a leap year
switch (monthInt)
{
case 1:
JOptionPane.showMessageDialog(null, "There are 31 days in January of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 2:
JOptionPane.showMessageDialog(null, "There are 28 days in February of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 3:
JOptionPane.showMessageDialog(null, "There are 31 days in March of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 4:
JOptionPane.showMessageDialog(null, "There are 30 days in April of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 5:
JOptionPane.showMessageDialog(null, "There are 31 days in May of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 6:
JOptionPane.showMessageDialog(null, "There are 30 days in June of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 7:
JOptionPane.showMessageDialog(null, "There are 31 days in July of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 8:
JOptionPane.showMessageDialog(null, "There are 31 days in August of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 9:
JOptionPane.showMessageDialog(null, "There are 30 days in September of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 10:
JOptionPane.showMessageDialog(null, "There are 31 days in October of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 11:
JOptionPane.showMessageDialog(null, "There are 30 days in November of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
case 12:
JOptionPane.showMessageDialog(null, "There are 31 days in December of" +yearIn, "", JOptionPane.PLAIN_MESSAGE);
break;
}
System.exit(0);
}
}
} //exit main method
The error occurs here:
Code:
else //The Year is NOT a leap year (not divisible by 4