//所以基本上对于下面的所有内容,我正在尝试对已生成的随机数进行排序,然后“排序”然后放入垃圾箱中,然后对于垃圾箱中有多少个数字,将打印一个星 *出每个号码。最后它看起来像一个直方图。像这样:
[0, 10) 中的 12 个随机整数排序到 2 个 bin 中:
******* 7 0.5833333 [5.0, 10.0)
***** 5 0.41666666 [0.0, 5.0) 但它就像它跳过最后两个方法一样 - generateBins 和 printBins。我将如何根据数字(如上)将随机数分类到 bin 中,并为该数组 bin 中的每个数字打印一个 *?
public class BinSort {
final int totalBins;
final int totalRandom;
final float widthBin;
int [] storeNumbers;
int [] binCount;
public BinSort (int nBins, int nSamples, int max) {
totalBins = nBins; //total # of bins, ie 2
totalRandom = nSamples; //total random number generated, ie 12
widthBin = (float) (max/totalBins); ie 2
int [] storeNumbers = new int [max];
for (int i = 0; i < totalRandom-1; i++) {
storeNumbers[i] = Random.rand(i, max);
System.out.println(storeNumbers[i]);
}
}
void generateBins () {
int [] binCount = new int [totalBins];
for (int i=0; i < totalRandom-1; i++) {
int bin = (int)(storeNumbers[i]/ totalBins);
Math.floor(bin);
bin = binCount [i];
}
}
void printBins () {
for (int i = 0; i < binCount.length - 1; i++) {
for (int j=0; j < binCount[j]; j ++) {
System.out.print("*");
System.out.println(); }
float freq = (binCount[i]/totalRandom);
float binMin = (i * widthBin);
float binMax = (binMin * widthBin);
System.out.print(binCount[i] + freq + binMin + binMax);
System.out.println();
}
}
}