Advertisement
Guest User

Untitled

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