1102自主学習

This commit is contained in:
2026-11-02 13:49:42 +09:00
parent c0101fc96d
commit 683be27ae1
18 changed files with 233 additions and 341 deletions

View File

@@ -11,13 +11,13 @@ public class Question16_4 {
int num2 = ageCheck(-5);
System.out.println("年齢は" + num2 + "です");
}catch(testException e) {
System.out.println(e.getMessage()+ "は不正な年齢です");
System.out.println(e.getAge()+ "は不正な年齢です");
}
}
public static int ageCheck(int num) throws testException {
if(num < 0) {
throw new testException("num");
throw new testException(num);
}
return num;
}

View File

@@ -1,6 +1,14 @@
public class testException extends Exception {
public testException(String message) {
super(message);
private final int age;
public testException(int num) {
this.age = num;
}
public int getAge() {
return age;
}
}