-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestArray2.java
More file actions
37 lines (33 loc) · 785 Bytes
/
TestArray2.java
File metadata and controls
37 lines (33 loc) · 785 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
27
28
29
30
31
32
33
34
35
36
37
import java.util.Scanner;
public class TestArray2{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入年份(YYYY)");
int y = sc.nextInt();
System.out.println("请输入月份(MM)");
int m = sc.nextInt();
System.out.println("请输入号数(DD)");
int d = sc.nextInt();
int t=0;
int[] data = new int[12];
for(int i=0; i<12; i++){
if(i == 1 ){
if((y%400 == 0) || (y%4 == 0 && y%100 != 0)){
data[i] = 29;
}else{
data[i] = 28;
}
}else if((i<=6) && (i%2==0)){
data[i] = 31;
}else if((i<=11) && (i%2!=0)){
data[i] = 31;
}else{
data[i] = 30;
}
}
for(int i=0; i<m-1; i++){
t = t+data[i];
}
System.out.println(y+"年"+m+"月"+d+"日 是该年的第"+(t+d)+"天");
}
}