-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProg14.java
More file actions
26 lines (23 loc) · 860 Bytes
/
Prog14.java
File metadata and controls
26 lines (23 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package org.project.test;
import java.util.Scanner;
public class Prog14 {
public static void main(String[] args){
Scanner scan = new Scanner(System.in).useDelimiter("\\D");//匹配非数字
System.out.print("请输入当前日期(年-月-日):");
int year = scan.nextInt();
int month = scan.nextInt();
int date = scan.nextInt();
scan.close();
System.out.println("今天是"+year+"年的第"+analysis(year,month,date)+"天");
}
//判断天数
private static int analysis(int year, int month, int date){
int n = 0;
int[] month_date = new int[] {0,31,28,31,30,31,30,31,31,30,31,30};
if((year%400)==0 || ((year%4)==0)&&((year%100)!=0))
month_date[2] = 29;
for(int i=0;i<month;i++)
n += month_date[i];
return n+date;
}
}