C语言实验——某年某月的天数(Java编写)
2018-03-18 11:12
387 查看
C语言实验——某年某月的天数
Time Limit: 1000 ms Memory Limit: 65536 KiBSubmit Statistic
Problem Description
输入年和月,判断该月有几天?
Input
输入年和月,格式为年\月。
Output
输出该月的天数。
Sample Input
2009\1
Sample Output
31
本题中需要注意两个地方,第一个地方就是在判断每月的天数额时候要注意有没有闰年的情况;另外在输入数据的时候要用Java的split函数做字符串 的分割,但是输入的数据中存在‘\’,这就需要转义来辨别,在Java中用\\\\来代替\\
//package hello; import java.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); String temp; int flag = 0; int days = 0; temp = cin.next(); String s[]; s = temp.split("\\\\"); int year, month; year = Integer.valueOf(s[0]); month = Integer.valueOf(s[1]); if((year%4==0&&year%100!=0)||(year%400==0)) flag=1; if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) days=31; if(month==4||month==6||month==9||month==11) days=30; if(flag==1&&month==2) days=29; if(flag==0&&month==2) days=28; System.out.println(days); cin.close(); } }
相关文章推荐
- C语言实验——某年某月的天数(java转义字符'\')
- C语言实验——某年某月的天数
- C语言实验——某年某月的天数
- C语言实验——某年某月的天数
- C语言实验——某年某月的天数
- JAVA语言实验——某年某月的天数
- java某年某月的天数
- C语言实验——某年某月的天数
- C语言实验——某年某月的天数
- c语言 某年某月的天数
- C语言实验——某年某月的天数
- oj1983: C语言实验——某年某月的天数
- [1160]C语言实验——某年某月的天数
- JAVA_某年某月的天数(split())
- java 获取某年某月的最大天数
- Java-判断某年某月的天数
- Problem G: C语言实验——某年某月的天数
- java循环某年某月的所有天数
- 求用JAVA计算某年某月的天数?(两种方法)
- 1160C语言实验——某年某月的天数