最近在复习软件测试顺便看到了这个例子,顺手实现了一下
public class test {
public static void main(String[] args) throws IOException
{
Scanner in=new Scanner(System.in);
System.out.println("input year");
int year=in.nextInt();
System.out.println("input month");
int month=in.nextInt();
System.out.println("input day");
int day=in.nextInt();
System.out.println("your input ls "+year+"."+month+"."+day);
System.out.println("the next day ls "+nextDay(year, month, day));
}
static String nextDay(int year,int month,int day)
{
String nextd="";
int dayfab=28;
int dayusual=30;
if((year%4==0 && year%100!=0) || (year%400==0))
dayfab=29;
if(month==1||month==3||month==5||month==7||month==8||month==10)
dayusual=31;
if(month==12)
{
if(day==31)
nextd=add(year+1, 1, 1);
else if(day<dayusual)
nextd=add(year, month, day+1);
else if(day>dayusual)
nextd="error day data";
}
else if(month==2)
{
if(day<dayfab)
{nextd=add(year, month, day+1);}
if(day==dayfab)
{nextd=add(year, month+1, 1);}
if(day>dayfab)
{nextd="error day data";}
}
else if(month>12)
{nextd="error month data";}
else
{if(day==dayusual)
nextd=add(year, month+1, 1);
else if(day<dayusual)
nextd=add(year, month, day+1);
else if(day>dayusual)
nextd="error day data";
}return nextd;
}
static String add(int year,int month,int day )
{
String time=Integer.toString(year)+"."+Integer.toString(month)+"."+Integer.toString(day);
return time;
}
}