Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void number(double[] data, int count) {
- this.data = data;
- size = count;
- }
- double getMean() {
- double sum = 0.0;
- for (double a : data)
- sum += a;
- return sum / size;
- }
- double getVariance() {
- double mean = getMean();
- double temp = 0;
- for (double a : data)
- if(a == 0.0){
- }else{
- temp += Math.pow(a-mean,2);
- }
- return temp / size;
- }
- double getStdDev() {
- return Math.sqrt(getVariance());
- }
- public void homework(String[] args) {
- TextIO txtIO = new TextIO();
- int num = 0;
- int count = 0;
- double sum = 0.0;
- boolean end = false;
- while (end == false) {
- double[] pole = new double[10];
- for (int i = 0; count < pole.length; count++) {
- String line = txtIO.getLine();
- num++;
- if (line.length() > 0 && txtIO.isDouble(line)) {
- sum = Double.parseDouble(line);
- if(count < 2){
- }else{
- pole[count] = sum;
- }
- }else{
- if (line.equals("")) {
- System.err.println("End of input detected!");
- end = true;
- break;
- }
- }
- }
- number(pole, count);
- System.out.printf(" "+count+" %.3f %.3f\n", getMean(), getStdDev());
- count = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement