Advertisement
ralphdc09

itf103.md-wk-11-wk-13.number03

May 15th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. package md.WK11toWK13;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class number03 {
  6.     public static void main(String[] args) {
  7.         Scanner ralph = new Scanner(System.in);
  8.  
  9.         int NumberOfDaysInMonth = 0;
  10.         String NameOfMonth = "Unknown";
  11.  
  12.         System.out.print("Input a month number: ");
  13.         int month = ralph.nextInt();
  14.  
  15.         System.out.print("Input a year: ");
  16.         int year = ralph.nextInt();
  17.  
  18.         /*
  19.         switch statement guide
  20.             Number of Days in Month:
  21.                January, March, May, July, August, October, December = 31
  22.                February = 28 or 29
  23.                April, June, September, November = 30
  24.             Leap Year:
  25.                if (( year % 400 is zero ) and (( year % 4 is zero ) or ( year % 100 is not zero))), Number of Days in February is 29
  26.                else Number of Days in February is 28
  27.          */
  28.         switch (month) {
  29.             case 1 -> {
  30.                 NameOfMonth = "January";
  31.                 NumberOfDaysInMonth = 31;
  32.             }
  33.             case 2 -> {
  34.                 NameOfMonth = "February";
  35.                 // leap year
  36.                 if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
  37.                     NumberOfDaysInMonth = 29;
  38.                 } else {
  39.                     NumberOfDaysInMonth = 28;
  40.                 }
  41.             }
  42.             case 3 -> {
  43.                 NameOfMonth = "March";
  44.                 NumberOfDaysInMonth = 31;
  45.             }
  46.             case 4 -> {
  47.                 NameOfMonth = "April";
  48.                 NumberOfDaysInMonth = 30;
  49.             }
  50.             case 5 -> {
  51.                 NameOfMonth = "May";
  52.                 NumberOfDaysInMonth = 31;
  53.             }
  54.             case 6 -> {
  55.                 NameOfMonth = "June";
  56.                 NumberOfDaysInMonth = 30;
  57.             }
  58.             case 7 -> {
  59.                 NameOfMonth = "July";
  60.                 NumberOfDaysInMonth = 31;
  61.             }
  62.             case 8 -> {
  63.                 NameOfMonth = "August";
  64.                 NumberOfDaysInMonth = 31;
  65.             }
  66.             case 9 -> {
  67.                 NameOfMonth = "September";
  68.                 NumberOfDaysInMonth = 30;
  69.             }
  70.             case 10 -> {
  71.                 NameOfMonth = "October";
  72.                 NumberOfDaysInMonth = 31;
  73.             }
  74.             case 11 -> {
  75.                 NameOfMonth = "November";
  76.                 NumberOfDaysInMonth = 30;
  77.             }
  78.             case 12 -> {
  79.                 NameOfMonth = "December";
  80.                 NumberOfDaysInMonth = 31;
  81.             }
  82.         }
  83.         System.out.print(NameOfMonth + " " + year + " has " + NumberOfDaysInMonth + " days! ");
  84.     }
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement