中級 › ArithmeticException: / by zero の原因と直し方 › パターン1
ArithmeticException: / by zero の原因と直し方
int型同士の割り算・剰余算で分母が0だと例外になります。
1 public class Main { 2 public static void main(String[] args) { 3 int total = 10; 4 int groups = __; ^ 5 System.out.println(total / groups); 6 } 7 }
Exception in thread "main" java.lang.ArithmeticException: / by zeroexited with code 1
空欄を埋めてビルドを通す
整数の0除算は例外になります。doubleの場合は例外ではなくInfinityになる点が違います。
次の問題