我正在做一个学校作业,所以我需要一些指导。我正在尝试编写一个从输入中读取一组浮点数据值的程序。当用户指示输入结束时,我的程序必须返回值的计数、平均值和标准偏差。
我能够构建 while 循环来获取输入并执行所有其他数学函数。但是,我无法弄清楚如何获取用户输入的值的计数。
这是我到目前为止所拥有的(减去循环)
        /**
    This class is used to calculate the average and standard deviation
    of a data set.
    */
    public class DataSet{
        private double sum;
        private double sumSquare;
        private int n;
        /**Constructs a DataSet ojbect to hold the
         * total number of inputs, sum and square
         */
        public DataSet(){
            sum = 0;
            sumSquare = 0;
            n = 0;
        }
        /**Adds a value to this data set
         * @param x the input value
         */
        public void add(double x){
            sum = sum + x;
            sumSquare = sumSquare + x * x;
        }
        /**Calculate average fo dataset
         * @return average, the average of the set
         */
        public double getAverage(){
            //This I know how to do
            return avg;
        }
        /**Get the total inputs values
         * @return n, the total number of inputs
         */
        public int getCount(){
//I am lost here, I don't know how to get this. 
        }
    }
我不能使用 Array,因为我们在课程上还没有那么远。