Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 数组[random]+的长代码是什么+;_Java_Arrays_Random_Increment - Fatal编程技术网

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