你好我正在做一個計算頻率分佈的程序,我在獲取類的數量時遇到了問題,因爲我打算在頻率分佈中使用它......類的結果是...
6.286797971382275,這是正確的,但...
我想這一輪關閉以7 ...
java中取整結果
我應該如何去做到這一點?謝謝
String []values = (inputValues.getText().toString().split(","));
int[] convertedValues = new int[values.length];
txtTotalNum.setText(Integer.toString(values.length));
//calculate for the minimum and maximum number
Arrays.sort(convertedValues);
int max=convertedValues[0];
for(int i=0;i<convertedValues.length;i++){
convertedValues[i] =Integer.parseInt(values[i]);
if(convertedValues[i]>max){
max=convertedValues[i];
}
}
int min = convertedValues[0];
double classes=0;
for(int i=0;i<convertedValues.length;i++){
convertedValues[i] =Integer.parseInt(values[i]);
if(convertedValues[i]<min){
min=convertedValues[i];
}
}
txtMinimum.setText(Integer.toString(min));
txtMaximum.setText(Integer.toString(max));
//calculate for the range
int range=max - min;
txtRange.setText(Integer.toString(range));
//calculate for the # of classes
classes=1+3.3*Math.log10(convertedValues.length);
Classes.setText(Double.toString(classes));
你爲什麼不使用類似'Math.ceil()'? –
你嘗試'Math.ceil()'嗎? – ahmedalkaff