200k views
1 vote
Write a method that returns the number of days in a year using the following header:

public static int numberOfDaysInAYear(int year)
Write a test program that displays the number of days in year from 2000 to 2020.
Name the project as FirstName_YourID_ProgramName, e.g. jack_12345_DaysInYear.

User BigRedDog
by
7.8k points

1 Answer

2 votes

Answer:

Step-by-step explanation:

Here is the code for the method:

```

public static int numberOfDaysInAYear(int year) {

if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {

return 366;

} else {

return 365;

}

}

```

Here is the code for the test program:

```

public class FirstName_YourID_DaysInYear {

public static void main(String[] args) {

for (int year = 2000; year <= 2020; year++) {

System.out.println(year + " has " + numberOfDaysInAYear(year) + " days.");

}

}

}

```

Make sure to replace "FirstName" and "YourID" with your own first name and ID number.

User NefariousOctopus
by
8.4k points