判断闰年以及随机月份天数-未调用类

来源:互联网 发布:mysql外键级联删除 编辑:程序博客网 时间:2024/05/02 23:24

package com.zhidi.test;

import java.util.GregorianCalendar;
import java.util.Scanner;

public class Runnian {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println(“请输入年份:”);
int year=sc.nextInt();
System.out.println(“请输入月份:”);
int month=sc.nextInt();
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
System.out.println(year+”年”+month+”月共31天”);
else if(month==4||month==6||month==9||month==11)
System.out.println(year+”年”+month+”月共30天”);
else if(month==2)
{
if(year%4==0 && (year%100!=0)||(year%400==0)){
System.out.println(year+”年”+month+”月共29天”);
}else{
System.out.println(year+”年”+month+”月共28天”);
}

    }    else{        System.out.println("输入有误,请重新输入:");    }}

}

0 0