中級 › ArithmeticException: / by zero の原因と直し方 › パターン2
ArithmeticException: / by zero の原因と直し方
int型同士の割り算・剰余算で分母が0だと例外になります。
1 public class Main { 2 public static void main(String[] args) { 3 int score = 87; 4 int bucket = __; ^ 5 System.out.println(score % bucket); 6 } 7 }
Exception in thread "main" java.lang.ArithmeticException: / by zeroexited with code 1
空欄を埋めてビルドを通す
剰余演算子(%)で0除算をしても、メッセージは / by zero のまま同じ例外が投げられます。/だけの問題ではありません。
次の問題