*6.16(一年的天数)使用下面的方法头编写一个方法,返回一年的天数: public static int numberOfDaysInAYear(int year) 编写一个测试程序,显示从2000年到2020年间每年的天数 *6.16(Number of days in a year) 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 the years between 2020 and 2034.
参考代码:
package chapter06;publicclassCode_16{publicstaticvoidmain(String[] args){for(int i =2000;i <=2020;i++)
System.out.printf("There are %d days in %d\n",numberOfDaysInAyear(i),i);}publicstaticintnumberOfDaysInAyear(int year){if(year %400==0||(year %4==0&& year %100!=0))return366;return365;}}
结果显示:
There are 366 days in 2000
There are 365 days in 2001
There are 365 days in 2002
There are 365 days in 2003
There are 366 days in 2004
There are 365 days in 2005
There are 365 days in 2006
There are 365 days in 2007
There are 366 days in 2008
There are 365 days in 2009
There are 365 days in 2010
There are 365 days in 2011
There are 366 days in 2012
There are 365 days in 2013
There are 365 days in 2014
There are 365 days in 2015
There are 366 days in 2016
There are 365 days in 2017
There are 365 days in 2018
There are 365 days in 2019
There are 366 days in 2020
Process finished with exit code 0
第六章第十六题(一年的天数)(Number of days in a year)*6.16(一年的天数)使用下面的方法头编写一个方法,返回一年的天数:public static int numberOfDaysInAYear(int year)编写一个测试程序,显示从2000年到2020年间每年的天数*6.16(Number of days in a year) Write a method that returns the number of days in a year using the f