-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice14.java
More file actions
63 lines (58 loc) · 1.5 KB
/
Copy pathPractice14.java
File metadata and controls
63 lines (58 loc) · 1.5 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package fiftypratice;
import java.util.Scanner;
/**
*
* 题目:输入某年某月某日,判断这一天是这一年的第几天?
*
*
* */
public class Practice14 {
public static void main(String[] args) {
int year=0,month=0,day=0;
int days=0;
Scanner s=new Scanner(System.in);
int input;
do{
input=0;
System.out.println("请输入年份:");
year=s.nextInt();
System.out.println("请输入月份:");
month=s.nextInt();
System.out.println("请输入日期:");
day=s.nextInt();
if(year<=0||month<=0||month>=12||day<=0||day>31){
System.out.println("输入有误,请重新输入!");
input=1;
}
}while(input==1);
if(s!=null){
s.close();
}
for(int i=1;i<month;i++){
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
break;
case 4:
case 6:
case 9:
case 11:
days=30;
break;
case 2:
if((year%400==0)||(year%4==0&&year%100!=0)){
days=29;
}else {days=28;}
break;
}
day=day+days;
}
System.out.println("这一天是这一年的第"+day+"天");
}
}