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 + "天");
    }

  • 相关阅读:
    vscode的一些常用、神奇操作
    vue2.x中使用v-model进行父传子
    js设置,获取,删除cookies
    Linux虚拟机克隆后网卡UUID问题
    jQuery ajax 请求HttpServlet返回[HTTP/1.1 405 Method not allowed]
    byte、二进制、十进制数值之间的转换
    sqlite-jdbc jar包下载过程笔记
    windows系统bat方式启动tomcat出现java.lang.OutOfmemoryError:PermGen Space 错误
    DIV内容垂直居中
    在HTML中实现和使用遮罩层
  • 原文地址:https://www.cnblogs.com/karmapeng/p/6295653.html
Copyright © 2011-2022 走看看