• 初学Java,写个demo
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
/*************************************************************************
> File Name: year_to_days.java
> Author: nemo_chen
> Created Time: Tue Aug 8 23:29:27 2017
************************************************************************/
import java.util.*;
public class year_to_days {
public static void main(String[] args){
int days = 0;
//user input
Scanner sc = new Scanner(System.in);
System.out.print("Please input yeads: ");
int year = sc.nextInt();
System.out.print("Please input mount: ");
int month = sc.nextInt();
switch(month){
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%4==0 && year%100!=0 || year%400==0)
days=29;
else
days=28;
break;
default:
System.out.println("month input error!");
System.exit(0);
}
System.out.printf("天数:%d\n", days);
}
}