初級 › variable might not have been initialized の原因と直し方 › パターン4
variable might not have been initialized の原因と直し方
ローカル変数は自動で初期化されません。
1 public class Main { 2 public static void main(String[] args) { 3 int result; 4 int n = 0; 5 while (n < 3) { 6 result = n; 7 n++; 8 } 9 System.out.println(______); ^ 10 } 11 }
Main.java:9: error: variable result might not have been initialized
空欄を埋めてビルドを通す
whileが1度も実行されない可能性がある限り、javacは値が入らない経路があると判断します。
次の問題