Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. void number(double[] data, int count) {
  2.         this.data = data;
  3.         size = count;
  4.     }
  5.  
  6.     double getMean() {
  7.         double sum = 0.0;
  8.         for (double a : data)
  9.             sum += a;
  10.         return sum / size;
  11.     }
  12.  
  13.     double getVariance() {
  14.         double mean = getMean();
  15.         double temp = 0;
  16.         for (double a : data)
  17.             if(a == 0.0){
  18.                
  19.             }else{
  20.             temp += Math.pow(a-mean,2);
  21.             }
  22.         return temp / size;
  23.     }
  24.  
  25.     double getStdDev() {
  26.         return Math.sqrt(getVariance());
  27.     }
  28.  
  29.  
  30.     public void homework(String[] args) {
  31.  
  32.         TextIO txtIO = new TextIO();
  33.         int num = 0;
  34.         int count = 0;
  35.         double sum = 0.0;
  36.        
  37.         boolean end = false;
  38.         while (end == false) {
  39.             double[] pole = new double[10];
  40.             for (int i = 0; count < pole.length; count++) {
  41.                 String line = txtIO.getLine();
  42.                 num++;
  43.                 if (line.length() > 0 && txtIO.isDouble(line)) {
  44.                     sum = Double.parseDouble(line);
  45.                     if(count < 2){
  46.  
  47.                     }else{
  48.                     pole[count] = sum;
  49.                     }
  50.                 }else{
  51.                 if (line.equals("")) {
  52.                     System.err.println("End of input detected!");
  53.                     end = true;
  54.                     break;
  55.  
  56.                 }
  57.                
  58.                 }
  59.                
  60.  
  61.             }
  62.             number(pole, count);
  63.             System.out.printf(" "+count+" %.3f %.3f\n", getMean(), getStdDev());
  64.             count = 0;
  65.            
  66.            
  67.         }
  68.  
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement