mport java.util.Scanner; import java.util.Date; public class Second { public static void main(String []args) { System.out.println("请输入你出生的年份"); int y=sc.nextInt(); System.out.println("请输入你出生的月份"); int m=sc.nextInt(); System.out.println("请输入你出生的日期"); int d=sc.nextInt(); Date date=new Date(); int y1=date.getYear()+1900; int m1=date.getMonth()+1; int d1=date.getDate(); int days=0; if(y1-y>1){ for(int i=y+1;i<y1;i++) { if(i%4==0 && i%100!=0 || i%400==0) { days+=366; }else{ days+=365; } } for(int i=1;i<m1;i++) { if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) { days+=31; }else if(i==2) { if(y1%4==0 && y1%100!=0 ||y1%400==0) { days+=29; }else{ days+=28; } }else{ days+=30; } } if(m==12) { days+=(31-d); }else{ for(int i =11;i>m;i--) { if(i==1||i==3||i==5||i==7||i==8||i==10) { days+=31; }else if(i==2) { if(y1%4==0 && y1%100!=0 ||y1%400==0) { days+=29; }else{ days+=28; } }else{ days+=30; } } } days=days+d1+d+2; System.out.println("您活了"+days+"天"); }else if(y1-y==1){ if(m==12) { for(int i=1;i<m1;i++) { if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) { days+=31; }else if(i==2) { if(y%4==0 && y%100!=0 ||y%400==0) { days+=29; }else{ days+=28; } } } days=days+d1+2+31-d; System.out.println("您活了"+days+"天"); }else{ for(int i=1;i<m1;i++) { if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) { days+=31; }else if(i==2) { if(y%4==0 && y%100!=0 ||y%400==0) { days+=29; }else{ days+=28; } }else { days+=30; } } for(int i=12;i>m;i--) { if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) { days+=31; }else if(i==2) { if(y%4==0 && y%100!=0 ||y%400==0) { days+=29; }else{ days+=28; } }else{ days+=30; } } days=days+(30-d)+d1; System.out.println("您活了"+days+"天"); } }else if(y1-y==0){ if(m1==m) { days=d1-d; System.out.println("您活了"+days+"天"); }else{ if(m1-m>1) { for(int i=m;i<m1;i++) { if(i==2) { if(y%4==0 && y%100!=0 || y%400==0) { days+=29; }else{ days+=28; } }else if(i==4||i==6||i==9||i==11) { days+=30; }else{ days+=31; } } days=days+d1+d; System.out.println("您活了"+days+"天"); }else if(m1-m==1){ if(d1==d) { if(m==2) { if(y%4==0 && y%100!=0 ||y%400==0){ days=29; System.out.println("您活了"+days+"天"); } }else if(m==4||m==6||m==9||m==11){ days=30; System.out.println("您活了"+days+"天"); }else{ days=31; System.out.println("您活了"+days+"天"); } }else if(d1>d){ if(m==2) { if(y%4==0 && y%100!=0 ||y%400==0){ days=29+(d1-d); System.out.println("您活了"+days+"天"); } }else if(m==4||m==6||m==9||m==11){ days=30+(d1-d); System.out.println("您活了"+days+"天"); }else{ days=31+(d1-d); System.out.println("您活了"+days+"天"); } }else{ if(m==2) { if(y%4==0 && y%100!=0 ||y%400==0){ days=29-d+d1; System.out.println("您活了"+days+"天"); } }else if(m==4||m==6||m==9||m==11){ days=30+(d1-d); System.out.println("您活了"+days+"天"); }else{ days=31+(d1-d); System.out.println("您活了"+days+"天"); } } } } } } }
时间: 2024-10-01 07:21:46