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: