【发布时间】:2015-05-20 05:13:52
【问题描述】:
我们在 Comsci 有一个我不知道的实验室。我在这个网站和其他网站上做了很多研究以寻求帮助,但他们超出了我的想象。让我失望的是阵列。无论如何,提前谢谢。我已经拿到了成绩,只是想知道如何做到这一点:D
PS:我的意思是,我只是找不到偶数中位数,我就放弃了。
import java.util.Arrays;
import java.util.Random;
public class TextLab06st
{
public static void main(String args[])
{
System.out.println("\nTextLab06\n");
System.out.print("Enter the quantity of random numbers ===>> ");
int listSize = Expo.enterInt();
System.out.println();
Statistics intList = new Statistics(listSize);
intList.randomize();
intList.computeMean();
intList.computeMedian();
intList.computeMode();
intList.displayStats();
System.out.println();
}
}
class Statistics
{
private int list[]; // the actual array of integers
private int size; // user-entered number of integers in the array
private double mean;
private double median;
private int mode;
public Statistics(int s)
{
size = s;
list = new int[size];
mean = median = mode = 0;
}
public void randomize()
{
Random rand = new Random(12345);
for (int k = 0; k < size; k++)
list[k] = rand.nextInt(31) + 1; // range of 1..31
}
public void computeMean()
{
double total=0;
for (int f = 0; f < size; f++)
{
total = total + list[f];
}
mean = total / size;
}
public void computeMedian()
{
int total2 = 0;
Arrays.sort(list);
if (size / 2 == 1)
{
// total2 =
}
else
{
total2 = size / 2;
median = list[total2];
}
}
public void computeMode()
{
// precondition: The list array has exactly 1 mode.
}
public void displayStats()
{
System.out.println(Arrays.toString(list));
System.out.println();
System.out.println("Mean: " + mean);
System.out.println("Median: " + median);
System.out.println("Mode: " + mode);
}
}
【问题讨论】:
-
到底是什么问题?
-
我认为他希望我们帮助他完成他的代码。我喜欢这些问题,所以我不介意^^。
-
@Shahzeb 对不起,是的。我的问题是找出如何完成 computeMean 和 computeMode 方法
-
为什么这个投票被否决了这么多?