import java.util.Scanner;
public class 算日子{
public static void main(String[] args){
boolean flag=true;
int year=0;
int month=0;
int date=0;
System.out.println("欢迎使用本系统!");
System.out.println("本系统支持计算某一天在一年中的第几天。");
System.out.print("请输入要计算的年份:");
Scanner userInput=new Scanner(System.in);
while (flag) {
year=userInput.nextInt();
if (year<1){
System.out.println("您输入的年份不合法,请重新输入:");
flag=true;
}else {
flag=false;
}
}
flag=true;
System.out.print("输入月份:");
while (flag) {
month=userInput.nextInt();
if (month<1||month>12){
System.out.println("您输入的月份不合法,请重新输入:");
flag=true;
}else {
flag=false;
}
}
flag=true;
System.out.print("输入日期:");
int a []={31,29,31,30,31,30,31,31,30,31,30,31};
while (flag) {
date=userInput.nextInt();
if (isRunNian(year)){
if (date<1||date>a[month-1]){
System.out.println(year+"年"+month+"月只有"+a[month-1]+"天,输入的日期不合法,请重新输入:");
flag=true;
}else {
flag=false;
}
}
else{
a[1]=28;
if (date<1||date>a[month-1]){
System.out.println(year+"年"+month+"月只有"+a[month-1]+"天,输入的日期不合法,请重新输入:");
flag=true;
}else {
flag=false;
}
}
}
if (isRunNian(year)){
System.out.println(year+"年为闰年");
int sum=0;
if (month==1){
System.out.print(year+"年"+month+"月"+date+"日为该年的第"+date+"天");
return;
}else{
for (int i=1;i<=month-1;i++){
sum+=a[i-1];
}
}
sum+=date;