java中怎样计算两个日期之间的天数

2024-10-28 13:26:43
推荐回答(1个)
回答(1):

import java.util.Scanner;
public class vb {
@SuppressWarnings("resource")
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入年份");
int yyy=sc.nextInt();
System.out.println("请输入月份");
int mmm=sc.nextInt();
boolean run=((yyy%4==0 && yyy%100!=0)||(yyy%400==0));
//System.out.print(run);
int days=0;
int yeardays=0;
int sumdays=0;
for(int i=1900;i if((i%4==0 && i%100!=0)||(i%400==0)){
yeardays+=366;
}else{
yeardays+=365;
}
}
for(int i=1;i switch(mmm){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days+=31;
break;
case 2:
if(run){
days+=29;
}else{
days+=28;
}break;
default:
days+=30;
break;
}
}