zoukankan      html  css  js  c++  java
  • 输入年份月份输出对应的天数

    方法1.

    //数据输入
    Scanner scanner=new Scanner(System.in);
    System.out.println("请输入年份(例如2012)");
    int year=scanner.nextInt();
    System.out.println("请输入月份");
    int mounth=scanner.nextInt();
    scanner.close();

    //判断是不是闰年
    boolean isrui=(year%4==0&&year%100!=0) || year%400==0;

    //判断月份
    if(isrui){
    switch(mounth){
    case 1:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 2:
    System.out.println(year+"年"+mounth+"月有"+29+"天");
    break;
    case 3:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 4:
    System.out.println(year+"年"+mounth+"月有"+30+"天");
    break;
    case 5:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 6:
    System.out.println(year+"年"+mounth+"月有"+30+"天");
    break;
    case 7:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 8:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 9:
    System.out.println(year+"年"+mounth+"月有"+30+"天");
    break;
    case 10:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 11:
    System.out.println(year+"年"+mounth+"月有"+30+"天");
    break;
    case 12:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    }
    }else{
    switch(mounth){
    case 1:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 2:
    System.out.println(year+"年"+mounth+"月有"+28+"天");
    break;
    case 3:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 4:
    System.out.println(year+"年"+mounth+"月有"+30+"天");
    break;
    case 5:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 6:
    System.out.println(year+"年"+mounth+"月有"+30+"天");
    break;
    case 7:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 8:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 9:
    System.out.println(year+"年"+mounth+"月有"+30+"天");
    break;
    case 10:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;
    case 11:
    System.out.println(year+"年"+mounth+"月有"+30+"天");
    break;
    case 12:
    System.out.println(year+"年"+mounth+"月有"+31+"天");
    break;

    }

    }

    方法二.

    Scanner s=new Scanner(System.in);
    System.out.println("请输入年份----");
    int a=s.nextInt();
    System.out.println("请输入月份----");
    int b=s.nextInt();
    int day=0;

    //可以输入,但是未完!!!
    switch(b){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    day=31;
    break;
    case 4:
    case 6:
    case 9:
    case 11:
    day=30;
    break;
    case 2:
    if((a%4==0&&(a%100!=0||(a%400==0)))){
    day=29;

    }else{
    day=28;
    }
    break;
    }
    System.out.println(a + "年" + b + "月份 " + "有" + day + "天");
    }

  • 相关阅读:
    boost库在windows下的编译和使用
    【转】VMware设置共享文件夹之后Ubuntu中看不到怎么办?
    ffmpeg常用命令
    虚函数和纯虚函数的作用与区别
    PJSIP UA分析
    PJSIP在windows(xp或者win7)下的编译,编译工具是vs2008,PJSIP版本2.3
    live555源码研究(十)------在编译过程中遇到的问题及解决方法
    live555源码研究(五)------DynamicRTSPServer类
    live555源码研究(四)------UserAuthenticationDatabase类
    web响应式图片设计实现
  • 原文地址:https://www.cnblogs.com/karmapeng/p/6295653.html
Copyright © 2011-2022 走看看