题解 | #获得月份天数#
获得月份天数
http://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNextInt()) {
int y = scan.nextInt();
int m = scan.nextInt();
if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {
if(m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
System.out.println("31");
} else if(m == 2) {
System.out.println("29");
} else if(m == 4 || m == 6 || m == 9 || m == 11){
System.out.println("30");
}
} else {
if(m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
System.out.println("31");
} else if(m == 2) {
System.out.println("28");
} else if(m == 4 || m == 6 || m == 9 || m == 11){
System.out.println("30");
}
}
}
}
}
Java基础练习题 文章被收录于专栏
都是一些基础的语法题目,每天可以刷几道。