If a user enters a numeric value of 1-12 for a month, how can I change my code below so that it displays the maximum number of days for this month entered by the user.
import java.util.*; public class LastDay { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); GregorianCalendar cal = new GregorianCalendar(); int myMonth; System.out.println("Enter the month number (1-12): "); myMonth = scanner.nextInt(); System.out.println("Maximum number of days is: " + Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH)); }
}
At the moment, he displays the maximum number of days in the month in which we are now (in March). I would like it to do this for myMonth value entered by the user.
source share