package AddOneDate;
import java.util.*;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
// TODO code application logic here
boolean flag=true;
int year=0,month=0,day=0;
StringTokenizer pas;
String date[]=new String[3];
String message[]= {"","",""};
while(flag)
{
flag=false;
String inputValue = JOptionPane.showInputDialog("請輸入年月日,輸入格式為:****/**/**");
pas = new StringTokenizer(inputValue,"//");
int i=0;
while(pas.hasMoreTokens())
date[i++]=pas.nextToken();
year=Integer.parseInt(date[0]);
month=Integer.parseInt(date[1]);
day=Integer.parseInt(date[2]);
if(year<=0) message[0]="你輸入的年份不合法!";
if(month<=0||month>12) message[1]="你輸入的月份不合法!";
switch(month)
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
{
if(day<=0||day>31)
message[2]="你輸入的日期不合法!";
break;
}
case 4:case 6:case 9:case 11:
{
if(day<=0||day>30)
message[2]="你輸入的日期不合法!";
break;
}
case 2:
{
if(year%4==0&&year%100!=0||year%400==0)
{
if(day<=0||day>=30)
message[2]="你輸入的日期不合法!";
break;
}
else
{
if(day<=0||day>=29)
message[2]="你輸入的日期不合法!";
break;
}
}
}
if(message[0].length()!=0||message[1].length()!=0||message[2].length()!=0)
{
flag=true;
for(int j=0;j<3;j++)
message[j]="";
JOptionPane.showMessageDialog(
null,
"你輸入的日期不合法!",
"警告信息",
JOptionPane.DEFAULT_OPTION );
}
}
System.out.println("你輸入的日期是:"+date[0]+"年"+date[1]+"月"+date[2]+"日");
switch(month)
{
case 1:case 3:case 5:case 7:case 8:case 10:
{
if(day<=30)
{day++;}
else
{
month++;day=1;
}
break;
}
case 4:case 6:case 9:case 11:
{
if(day<=29)
{day++;}
else
{day=1;month++;}
break;
}
case 2:
{
if(year%4==0&&year%100!=0||year%400==0)
{
if(day<=28){day++;}
else
{day=1;month++;}
}
else
{
if(day<=27){day++;}
else
{day=1;month++;}
}
break;
}
case 12:
{
if(day<=30){day++;}
else
{day=1;month=1;year++;}
break;
}
}
System.out.println("第二天的日期為:"+year+"年"+month+"月"+day+"日");
}
}