zoukankan      html  css  js  c++  java
  • 某个日期的下一天

    /**
    * 功能:输入1990至2020年间的某个日期
    * 输出该日期的下一天
    * @author hey_boom;
    */
    import java.util.Scanner;

    public class dataTest {

    int year;
    int month;
    int day;
    public dataTest(){
    System.out.println(" 请输入年份(1990至2020年间):");
    Scanner scanyear = new Scanner(System.in);
    year = scanyear.nextInt();
    System.out.println(" 请输入月份:");
    Scanner scanmonth = new Scanner(System.in);
    month = scanmonth.nextInt();
    System.out.println(" 请输入日号:");
    Scanner scanday = new Scanner(System.in);
    day = scanday.nextInt();
    System.out.println("你输入的日期"+year+"年"+month+"月"+day+"日 ");
    if(year<1990||year>2020){
    System.out.println(" 输入非法:输入数据不在判断范围内!! ");
    }
    else if(!isRun(year)&&month==2&&day==29){
    System.out.println(" 输入非法:该年份是平年,2月月末是28号!! ");
    }
    else{
    /*闰年2月*/
    if(isRun(year)&&month==2&&day==28){
    month=3;
    day=29;
    }
    else if(isRun(year)&&month==2&&day==29){
    month++;
    day=1;
    }
    else if(!isRun(year)&&month==2&&day==28){
    month++;
    day=1;
    }
    /*年末*/
    else if(month==12&&day==31){
    year++;
    month=1;
    day=1;
    }
    /*月末*/
    else if((month==1||month==3||month==5||month==7||month==8||month==10)&&day==31){
    month++;
    day=1;
    }
    else if((month==4||month==6||month==11)&&(day==30)){
    month++;
    day=1;
    }
    /*其他*/
    else{
    day++;
    }
    System.out.println(" 该日期的下一天:"+year+"年"+month+"月"+day+"日");
    }

    }

    /*判断闰年*/
    public boolean isRun(int year){
    if((year%4==0&&year%100!=0)||(year%400==0))
    return true;
    else
    return false;
    }

    public static void main(String[] args){
    while(true){
    System.out.println(" *************************************");
    new dataTest();
    }
    }
    }

  • 相关阅读:
    cf359D Pair of Numbers
    cf671B Robin Hood
    [暑假集训--数位dp]hdu5787 K-wolf Number
    [暑假集训--数位dp]UESTC250 windy数
    [暑假集训--数位dp]LightOj1205 Palindromic Numbers
    [暑假集训--数位dp]LightOJ1140 How Many Zeroes?
    [暑假集训--数位dp]LightOj1032 Fast Bit Calculations
    [暑假集训--数位dp]hdu5898 odd-even number
    [暑假集训--数位dp]cf55D Beautiful numbers
    [暑假集训--数位dp]hdu3709 Balanced Number
  • 原文地址:https://www.cnblogs.com/heyboom/p/7827360.html
Copyright © 2011-2022 走看看