Java小程序:根据年份,月份来判断大小月

package day04;

import java.util.Scanner;

public class MonthDemo {

public static void main(String[] args) {

System.out.println(“请在控制台输入年份和月份”);

Scanner scan=new Scanner(System.in);

int year=scan.nextInt();

int month=scan.nextInt();

int days=0;

switch(month){
case 2:

boolean flag=(year%4==0&&year%100!=100)||year%400==0;
if(flag){
  days=29;
}else{
  days=28;
}

break;
case 4:
case 6:
case 9:
case 11:
days=30;
break;
default:
days=31;
break;
}
System.out.println(year+“年”+month+“月有”+days+“天”);
}

你可能感兴趣的:(小练习)