Skip to content

Instantly share code, notes, and snippets.

@nk4dev
Created May 22, 2023 02:15
Show Gist options
  • Save nk4dev/ca62837fef095d6b7bebff1318acb2d4 to your computer and use it in GitHub Desktop.
Save nk4dev/ca62837fef095d6b7bebff1318acb2d4 to your computer and use it in GitHub Desktop.
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.");
}
}
}
@nk4dev
Copy link
Author

nk4dev commented May 22, 2023

update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment