您的位置:首页 > 编程语言 > C语言/C++

C语言实验——某年某月的天数(java转义字符'\')

2017-03-08 11:14 567 查看


C语言实验——某年某月的天数

Time Limit: 1000MS Memory Limit: 65536KB

Submit Statistic


Problem Description

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


Input

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


Output

输出该月的天数。


Example Input

2009\1



Example Output

31



Hint

注意判断闰年啊


Author

import java.util.*;
import java.math.*;
public class Main {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String line = input.nextLine().trim();
String array[] = line.split("\\\\");
int year = Integer.parseInt(array[0]);
int month = Integer.parseInt(array[1]);
int day=0;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day = 31;
break;
case 2:
if((year%100!=0&&year%4==0)||(year%400==0))
{
day = 29;
}
else day = 28;
break;
case 4:
case 6:
case 9:
case 11:
day = 30;
break;

}
System.out.println(day);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: