JAVA_某年某月的天数(split())

来源:互联网 发布:如何查询淘宝商品类目 编辑:程序博客网 时间:2024/05/17 08:11

某年某月的天数

Time Limit: 1000MS Memory Limit: 65536KB 

Problem Description

输入年和月,判断该月有几天?

Input

输入年和月,格式为年\月。

Output

输出该月的天数。

Example Input

2009\1

Example Output

31

Hint

注意判断闰年啊

01import java.util.*;
02 
03public class Main {
04        public static void main(String args[]){
05            Scanner input = new Scanner(System.in);
06            int s = 0;
07                        String aa = null;
08                        aa = input.nextLine();
09                        String[] bb = aa.split("\\\\");
10                         
11                        int[] cc = new int[bb.length];
12                        for(int i = 0;i<bb.length;i++){
13                             
14                            cc[i] = Integer.parseInt(bb[i]);
15                        }
16 
17             switch(cc[1])  
18                {  
19                    case 1:  
20                        s=31;  
21                        break;  
22                    case 2:  
23                    if((cc[0]%4==0&&cc[0]%100!=0)||(cc[0]%400==0))  //判断闰年  
24                        s=29;  
25                    else s=28;  
26                    break;  
27                    case 3:  
28                        s=31;  
29                        break;  
30                    case 4:  
31                        s=30;  
32                        break;  
33                    case 5:  
34                        s=31;  
35                        break;  
36                    case 6:  
37                        s=30;  
38                        break;  
39                    case 7:  
40                        s=31;  
41                        break;  
42                    case 8:  
43                        s=31;  
44                        break;  
45                    case 9:  
46                        s=30;  
47                        break;  
48                    case 10:  
49                        s=31;  
50                        break;  
51                    case 11:  
52                        s=30;  
53                        break;  
54                    case 12:  
55                        s=31;  
56                        break;  
57                }
58            System.out.println(s);
59        }
60}
61 




0 0
原创粉丝点击