0
import java.util.Random;
public class test{
public static void main(String[] args){
System.out.println(qq(30));
}
public static int qq(int range){
Random generator=new Random();
int[] aa = new int[range]; //create an array with "range" elements
for (int w=0;w <range;w++) {
aa[w] = generator.nextInt(20);// assign random numbers to array aa
}
int ee=0; //number of times
outerloop:
for(int i =0;i<range;i++){
for(int j=i+1;j<range-1;j++){
if (aa[i]==aa[j]){
break outerloop;//if aa[i] and aa[j] are the same,break and return ee
}
else{
ee++; //if aa[i] and aa[j] are not the same, ee++ and keep going
}
}
}
return ee;//return the min number of failed match attempts
}
}
私はこのプログラムを10回繰り返します(10 "ee"を受信します)。これらの結果を保存するにはどうすればこれらの10個の数字を使うことができますか?後で平均を見つける。私は何度もプログラムを繰り返したい。これらの結果を別のクラスに記録するにはどうすればいいですか?
クラスが実際に話していることは記録できません。あなたは結果をファイルに書き出すことができます。それはかなり正常です。 – markspace
OTOHでは、 'main'で' qq() 'を呼び出すと、それをループに入れ、結果を配列に記録することができます。 – markspace
あなたは正しいです!ありがとう –