i need to modify the following code so that i can input a given year and count its days, considering that leap years have a day more than the others. I think the Scanner function and if statements would be useful here but i am confused on how to modify the code .
public class Homework {
public static void main(final String[] args)
{
final String[] months =
{
"January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"
};
final int[] days = {31, 28 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//Print out days for each month and add them
int total = 0;
for (int m = 0; m < months.length; m++) {
System.out.println(months[m] + " has " + days[m] + " days.");
total += days[m];
}
System.out.println("===================\nTotal" + total + " days");
}
}
Also, i need to calculate the total number of days over all years from 1900 to 1999 (inclusive). The program will be neater if i write a method that takes a year as its parameter and returns the total number of days in that year but again, i am confused about the specifics of it.
Thanks!