栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java做万年历

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java做万年历

1.判断输入的年份是否为闰年

2.判断输入月份的天数

3.判断输入月份的第一天为星期几 

package com.yc;
import java.util.*;
public class calendar {
    public static void main(String []args) {
        int year=0,month=0;//定义年份和月份
        boolean yn=false;
        int monthofday=0;//定义每个月的天数
        int monthday=0,yearday=0,allday=0;
        int firstweek=0;
        Scanner sc=new Scanner(System.in);//数据键盘输入
        System.out.println("**************************欢迎使用万年历*******************");
        System.out.println("请输入年份:");
        if(sc.hasNextInt()) {//判断键盘输入的数据类型是否出错
            year=sc.nextInt();
            if(year<1900||year>9999) {
                System.out.println("年份输入错误,请从新输入:");
                if(sc.hasNextInt()) {
                    year=sc.nextInt();
                }else {
                    System.out.println("年份输入错误!");
                    System.exit(0);//直接跳出系统
                }
            }
        }else {
            System.out.println("年份输入错误!");
            System.exit(0);//直接跳出系统
        }
        System.out.println("请输入月份:");
        if(sc.hasNextInt()) {
            month=sc.nextInt();
            if(month<1||month>12) {
                System.out.println("月份输入错误,请从新输入:");
                if(sc.hasNextInt()) {
                    month=sc.nextInt();
                }else {
                    System.out.println("月份输入错误!");
                    System.exit(0);//直接跳出系统
                }
            }
        }else {
            System.out.println("月份输入错误!");
            System.exit(0);//直接跳出系统
        }
        if(year%4==0&&year%100!=0||year%400==0)//判断是否是闰年
            yn=true;
        switch(month) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:monthofday=31;break;
        case 4:
        case 6:
        case 9:
        case 11:monthofday=30;break;
        case 2:if(yn)
                    monthofday=29;
               else
                    monthofday=28;
        
        }
        //计算1900~当前年份之前所有的天数
        for( int y=1900;y 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/878072.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号