Created
January 7, 2015 07:55
-
-
Save takanakahiko/3edfa01cce6c5d1146e5 to your computer and use it in GitHub Desktop.
例外クラスの作成の学習。これでも正しいのかさっぱり(1.7)
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
class EvenException extends Exception{}; | |
class OddException extends Exception{}; | |
class Even{ | |
static void isEven(int i) throws EvenException, OddException{ | |
if(i%2 == 0){ | |
throw new EvenException(); | |
}else{ | |
throw new OddException(); | |
} | |
} | |
public static void main(String[] args){ | |
int n = Integer.parseInt(System.console().readLine("数字を入力してください ->")); | |
try{ | |
isEven(n); | |
}catch(EvenException e){ | |
System.out.println("偶数です"); | |
}catch(OddException e){ | |
System.out.println("奇数です"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment