while循環開始之前的語句System.out.println("Value of i before loop = " + i);
未被打印,並且循環中的值i
未從1開始打印。而是從隨機大int開始打印。while()循環的問題
package main;
import java.util.Random;
public class Main {
public static void main(String args[]){
Random ran = new Random();
int[] in = {2,5,9};
int[] c_gen = new int[3];
int i = 0;
System.out.println("Value of i before loop = " + i);
while(!(c_gen.equals(in))){
c_gen[0] = ran.nextInt(10);
c_gen[1] = ran.nextInt(10);
c_gen[2] = ran.nextInt(10);
i++;
System.out.println(c_gen[0] + " " + c_gen[1] + " " + c_gen[2] + " .................." + i);
}
System.out.print("in = ");
for(int x : in)
System.out.print(x + " ");
System.out.print("\n" + "c_gen = ");
for(int x : c_gen)
System.out.print(x + " ");
System.out.println("\n" + "i = " + i);
}
}
我沒有看到任何這樣的行爲在你的[代碼](HTTP: //ideone.com/zDe7Ll)如你所描述的事實你有一個無限循環它意味着條件總是如此,所以你需要搜索如何比較數組 – silentprogrammer