import java.util.Random;
class arel {
public static void main(String args[]){
Random rand = new Random();
int[] number = new int[7];
for(int roll = 1; roll < 100; roll++){
++number[1+rand.nextInt(6)];
}
System.out.println("Index\tValue");
for(int count = 1; count<number.length; count++){
System.out.println(count+"\t"+number[count]);
}
}
}
++number[1+rand.nextInt(6)];
是那條線意味着插入每個索引的隨機數?可能會有人解釋這個java循環對我來說
我假設你的意思是行數++數[1 + rand.nextInt(6)];'? –
'++ number [1 + rand.nextInt(6)]'將數組'number'的隨機成員1到6增加一個 – PeterT
您正在預先遞增數組的一個元素,同時將霧擴散到整個你的代碼在這裏。這裏發生的事情是,一個理貨正在增加。我會這樣做:number [1 + rand.nextInt(6)] + = 1; – ncmathsadist