THINK FIRST·CODE LATER

← All labs

Days in a month (leap years)

Problem

Write a class DaysInMonth that reads a year and a month (1–12) and prints the number of days, as Days: 29.

A year is a leap year when it is divisible by 4, except years divisible by 100, unless they are also divisible by 400. So 2000 is a leap year, 1900 is not.

If the month is not between 1 and 12, print Invalid month.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.