UT source 065 (java Version)

Source: Internet
Author: User

nextdate function problems

The Nextdate function describes a complex relationship, that is, the complexity of the logical relationship between input variables

The Nextdate function contains three variables, month, day, and year, and the output of the function is the date after the date Entered. The input variables are required to be integer values of month, day, and year, and the following conditions are Met:

Condition 1 1≤month≤12 Otherwise output, month out of range

Condition 2 1≤day≤31 Otherwise output, date out of range

Condition 3 1912≤year≤2050 Otherwise output: year out of range

String nextdate (int m,int d,int y)

Note The return value is a string.

Program Requirements:

1) first show "please enter date"

2) does not satisfy the condition 1, returns: "the month out of range", does not satisfy the condition 2, returns: "date out of range", does not satisfy the condition 3, returns: "the year out of range", if there are multiple unsatisfied, the first occurrence of unsatisfied error return Information.

3) If the conditions are met, the date of the second day is output: format "* * * * Month * * * day" (if you enter December 31, 2050, the normal January 1, 2051

Package Examone;import Java.util.scanner;public class Date {String ia, ib, ic;int y, m, d;private boolean Read () {Scanner s c = new Scanner (system.in); System.out.println ("please Enter the year"); ia = sc.nextline (); if ("-1". equals (ia)) {sc.close (); return false;} System.out.println ("please Enter the month"); IB = Sc.nextline (); System.out.println ("please Enter date"); IC = sc.nextline (); return true;} Private Boolean Isinputinteger () {try{y = integer.valueof (ia). intvalue (); m = integer.valueof (ib). intvalue ();d = Integer.valueof (ic). intvalue (); return true;} Catch (Exception e) {System.out.println ("input not required, enter three integers"); return false;}} Private Boolean Isinrange () {if (m < 1 | | m >) {System.out.println ("month out of range"); return false;} If (d < 1 | | d >) {System.out.println ("date out of range"); return false;} If (y < 1912 | | y > 2050) {System.out.println ("year out of range"); return false;} Return true;} private int isleapyear () {if ((y% 4 = = 0 && y% 100! = 0) | | (y% 400 = = 0)) {return 1;} Return 0;} Private Boolean Endofmouth (int flg) {if ((m = = 1 || m = = 3 | | m = = 5 | | m = = 7 | | m = = 8 | | m = = 10 | |    m = =) && D = = +) {return true;    } if (m = = 2 && d = = (+ flg)) {return true;    } if ((m = = 4 | | m = = 6 | | m = = 9 | | m = = One) && d = =) {return true; } return false;} Private String nextdate () {int tag = 0;if (endofmouth (isleapyear ())) {tag = 1;} if (m = = && Tag = = 1) {y++;m = 1;d = 1;} else if (tag = = 1) {m++;d = 1;} else{d++;} String ret = y + "year" + m + "month" + D + "day"; return ret;} public static void main (String Args[]) {date solve = new Date (), while (solve. Read ()) {if (solve.isinputinteger () && solve.isinrange ()) {System.out.println (solve. Nextdate ());}}}

  

UT source 065 (java Version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.