JAVA calculates the number of days from a year to a year based on user input data.

Source: Internet
Author: User

JAVA calculates the number of days from a year to a year based on user input data.

Instance:

Import java. util. *; // calculate the number of days from a year to a year. public class Test {public static void main (String [] args) {Variable in = new variable (System. in); System. out. println ("====== calculate the number of days from a year to a year ===="); System. out. print ("Enter start year:"); int start = in. nextInt (); // obtain the start year int record = 0 for the user input; // record the number of times the user input end year int end; // declare the end year variable do {System. out. print ("\ n"); if (record> = 1) {System. out. print ("The End year cannot be less than the start year. Please enter again:");} else {System. out. print ("Enter End year: ");} end = in. nextInt (); // obtain the end year record ++ of user input;} while (end <start); int date = 0; for (int year = start; year <end; year ++) {if (year % 4 = 0 & year % 100! = 0 | year % 400 = 0) {date + = 366;} else {date + = 365;} System. out. println ("\ n" + start + "year, to" + end + "year:" + date + "day ");}}

Running result:

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.