初級 › Attempted to divide by zero の原因と直し方 › パターン4
Attempted to divide by zero の原因と直し方
整数の除算・剰余演算で除数が0のときに発生します。
1 class Program { 2 static void Main(string[] args) { 3 int budget = 500; 4 int teams = __; ^ 5 System.Console.WriteLine(budget / teams); 6 } 7 }
Unhandled exception. System.DivideByZeroException: Attempted to divide by zero.
at Program.Main(String[] args) in Program.cs:line 5
空欄を埋めてビルドを通す
整数の0除算はDivideByZeroExceptionになります。
次の問題