所以我一直在研究这个程序,我已经得到了一些可以很好地解决的日期,但是当我输入未来年份的二月份时,它显示它不应该是无效的。为了这个计划,2 月份的天数只有 1-28 天。谁能帮我抓住我的错误?
import java.util.Scanner;
public class FutureDate {
public static void main (String args[]){
int inputMonth;
int inputDate;
int inputYear;
final int currentMonth = 10;
final int currentDate = 24;
final int currentYear = 2013;
final int numberOfDays = 31;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a month in format - mm: ");
inputMonth = keyboard.nextInt();
System.out.println("Enter a day in format - dd: ");
inputDate= keyboard.nextInt();
System.out.println("Enter a year in format - yyyy: ");
inputYear = keyboard.nextInt();
if (inputYear < currentYear)
System.out.println("Invalid Date");
else if (inputYear >= currentYear)
{
if (inputMonth >= 1 && inputMonth <=12){
if ((inputMonth == 4 || inputMonth == 6 || inputMonth == 9 || inputMonth == 11) && (inputDate >= 1 && inputDate <= 30))
System.out.println("Valid Date");
else if (inputMonth > currentMonth && inputDate >= 1 && inputDate <=30)
System.out.println("Valid Date");
else if (inputMonth == currentMonth && inputDate > currentDate && inputDate <=30)
System.out.println("Valid Date");
else
System.out.println("Invalid Date");
}
else if (inputMonth == 2 && inputDate >= 1 && inputDate <= 28){
System.out.println("Valid Date");
if (inputMonth > currentMonth && inputDate >= 1 && inputDate <=28)
System.out.println("Valid Date");
else if (inputMonth == currentMonth && inputDate > currentDate && inputDate<=28)
System.out.println("Valid Date");
else
System.out.println("Invalid Date");
}
else if (inputMonth == 1 || inputMonth == 3 || inputMonth == 5 || inputMonth == 7 || inputMonth ==10 || inputMonth == 12 && inputDate >= 1 && inputDate <= 31){
if (inputMonth > currentMonth && inputDate >= 1 && inputDate <=31)
System.out.println("Valid Date");
else if (inputMonth == currentMonth && inputDate > currentDate && inputDate <=31)
System.out.println("Valid Date");
else
System.out.println("Invalid Date");
}
else
System.out.println ("Invalid Date");
}
}
}