Java 数组[random]+的长代码是什么+;
Java 数组[random]+的长代码是什么+;,java,arrays,random,increment,Java,Arrays,Random,Increment,freq[1+dice.nextInt(6)]++的长代码是什么 既然a++是a=a+1那么array[random]++是 这是我的密码 Random dice = new Random(); int freq[] = new int[7]; for(int roll=0;roll<1000;roll++){ ++freq[1+dice.nextInt(6)]; } System.out.println("Face\tFrequency"); for(int face=1;
freq[1+dice.nextInt(6)]++的长代码是什么代码>
既然a++
是a=a+1
那么array[random]++
是
这是我的密码
Random dice = new Random();
int freq[] = new int[7];
for(int roll=0;roll<1000;roll++){
++freq[1+dice.nextInt(6)];
}
System.out.println("Face\tFrequency");
for(int face=1;face<freq.length;face++){
System.out.println(face + "\t" + freq[face]);
}
Random dice=new Random();
int freq[]=新的int[7];
对于(int roll=0;roll
是:
或者,甚至更长的时间:
int index = 1+dice.nextInt(6);
int value = freq[index]; // Get the value
++value; // Increment the value
freq[index] = value; // Resave
你所说的“长方法”是什么意思?我的意思是“长代码”。编辑。谢谢你的回复,但我的意思是这样的…a++;是a=a+1;我在那里的更新将代码一步一步地写出来。
int index = 1+dice.nextInt(6);
++freq[index]; // Increment that position
int index = 1+dice.nextInt(6);
int value = freq[index]; // Get the value
++value; // Increment the value
freq[index] = value; // Resave