利用switch的形式编程实现计算月份天数。 程序运行时用户输入具体的年份和月份,然后输出对应的年

import java.util.Scanner;

public class demo4 {
//private static int [] month1={31,28,31,30,31,30,31,30,31,30,31,30};
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print(“输入年份:”);
int year = input.nextInt();
System.out.print(“输入月份:”);
int month = input.nextInt();

    if(year%4==0||year%400==0)
    {
    	System.out.print(year);
    	System.out.print("闰年");
    }
    else{
    	System.out.print("平年");
    }
    
    switch(month)
    {
    case 1:System.out.print("一月-");System.out.print("31");break;
    case 2:System.out.print("二月-");System.out.print("28");break;
    case 3:System.out.print("三月-");System.out.print("31");break;
    case 4:System.out.print("四月-");System.out.print("30");break;
    case 5:System.out.print("五月-");System.out.print("31");break;
    case 6:System.out.print("六月-");System.out.print("30");break;
    case 7:System.out.print("七月-");System.out.print("31");break;
    case 8:System.out.print("八月-");System.out.print("30");break;
    case 9:System.out.print("九月-");System.out.print("31");break;
    case 10:System.out.print("十月-");System.out.print("30");break;
    case 11:System.out.print("十一月-");System.out.print("31");break;
    case 12:System.out.print("十二月-");System.out.print("30");break;
    
    }
    
    
    input.close();
}

你可能感兴趣的:(Java编程)