I am working on this porgram that asks the user for a month, day and year, the program then needs to check to see if the input in valid and also check to see if the year input is a leap year or not, I have most of the code written out and had it working but I changed something around and cannot get it to compile again, keeps giving me an error of else without if but I dont understand how it gets that error, I also have a problem with the validity of the input, when an input is outside the range nothing prints from the system out print lines, Im not quite sure why either, so if anyone can point out my mistakes Id greatly appreciate it, thanks in advanced----Dinty
import java.util.Scanner;
public class Dates2
{
public static void main(String[] args)
{
int month, day, year; //date read in from user
int daysInMonth; //number of days in month read in
int monthValid; //true if input from user is valid
int yearValid;
int dayValid;
int leapYear; //true if user's year is a leap year
Scanner scan = new Scanner(System.in);
System.out.print( " Please enter a month in number form ");
month = scan.nextInt( );
System.out.print( " Please enter a day in number form ");
day = scan.nextInt( );
System.out.print( " Please enter a year in number form ");
year = scan.nextInt( );
if ( month >= 1 && month <= 12)
if ( day >= 1 && day <= 31)
if ( year >= 1000 && year <= 1999)
{
System.out.println( " The date entered is valid. ");
}
else
{
if( month <= 0 || month > 12)
System.out.println( " Input Invalid, Please Try Again1. ");
}
{
if( day < 1 || day > 31)
System.out.println( " Input Invalid, Please Try Again2. ");
}
{
if ( year < 1000 || year > 1999)
System.out.println( " Input Invalid, Please Try Again3. ");
}
else
{
if ( year % 400 == 0)
System.out.println(" It's a Leap Year!");
}
{
if (year % 4 == 0 && year % 100 != 0)
System.out.println(" The year is not a Leap Year. ");
}
}
}