Practice judging the number of days in a month

The code is as follows:

/*Enter a year and month, and output the corresponding days of the month * / import Java util. Scanner; Class demo10 {public static void main (string [] args) {scanner SC = new scanner (system. In); system. Out. Println ("please enter year and month"); int year = sc.nextint(); int month = sc.nextint(); / / judge the number of days of the month int days = 0; switch (month) {case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; case 2: if (year% 4 = = 0 & & year% 100! = 0 | year% 400 = = 0) days=29; else days=28; break; case 4: case 6: case 9: case 11: days=30; break; default: System. out. Println ("the number representing the month you entered is unreasonable, please re-enter");} System. out. Println (year + "year" + month + "month:" + days + "day");}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>