Created
May 22, 2023 02:15
-
-
Save nk4dev/ca62837fef095d6b7bebff1318acb2d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class f22aa021_Maeda { | |
public static void main(String[] args) { | |
// Exception handling with Try Catch System. | |
// case to determine the month -> if it is over 12, it is treated as an exception. | |
// write by Nknight AMAMIYA. | |
try { | |
Scanner sc = new Scanner(System.in); | |
Integer intake = sc.nextInt(); | |
String latestMonthDay = switch (intake) { | |
case 1 -> "31"; | |
case 2 -> "28"; | |
case 3 -> "31"; | |
case 4 -> "30"; | |
case 5 -> "31"; | |
case 6 -> "30"; | |
case 7 -> "31"; | |
case 8 -> "31"; | |
case 9 -> "30"; | |
case 10 -> "31"; | |
case 11 -> "30"; | |
case 12 -> "31"; | |
default -> "error"; | |
}; | |
StringBuilder sb = new StringBuilder(); | |
if (latestMonthDay.equals("error")) { | |
System.out.println("please input value of 1 - 12!"); | |
} else { | |
sb.append(intake+ "is"); | |
sb.append(latestMonthDay); | |
System.out.println(sb); | |
} | |
} catch (Exception e) { | |
System.out.println("input int."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update.