programmingex4 17 java

Solutions on MaxInterview for programmingex4 17 java by the best coders in the world

showing results for - "programmingex4 17 java"
Damián
16 Jun 2020
1import java.util.Scanner;
2 
3public class ProgrammingEX4_17 {
4 
5 public static void main(String[] args) {
6 
7  Scanner input = new Scanner(System.in);
8  System.out.print("Enter a year:");
9  int year = input.nextInt();
10 
11  System.out.print("Enter a month:");
12  String month = input.next();
13 
14  int days = 0;
15 
16  switch (month) {
17  case "Feb":
18   if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
19    days = 29;
20    break;
21   }
22   days = 28;
23   break;
24 
25  case "Apr":
26  case "Jun":
27  case "Sep":
28  case "Nov":
29   days = 30;
30   break;
31 
32  case "Jan":
33  case "Mar":
34  case "May":
35  case "Jul":
36  case "Aug":
37  case "Oct":
38  case "Dec":
39   days = 31;
40   break;
41 
42  default:
43   System.out.println("Invalid month.");
44   System.exit(0);
45 
46  }
47 
48  System.out.println(month + " " + year + " has " + days + " days");
49 }
50}
51
similar questions
queries leading to this page
programmingex4 17 java