与えられる: public class TestLoop { public static void main(String[] args) { int array[] = {0, 1, 2, 3, 4}; int key = 3; for (int pos = 0; pos < array.length; ++pos) { if (array[pos] == key) { break; } } System.out.print("Found " + key + "at " + pos); } } 結果は何ですか?
正解:C
The following line does not compile: System.out.print("Found " + key + "at " + pos); The variable pos is undefined at this line, as its scope is only valid in the for loop. Any variables created inside of a loop are LOCAL TO THE LOOP.