turt2live

Untitled

Oct 27th, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1.         String data = "(1) 1.034 (2) 33.7 (3) 33.1 (4) 31.8 (5) 30.1 (6) 33.2 (7) 33.4 (8) 48.7 (9) 36.6 (10) 35.7";
  2.         String[] parts = data.split(" ");
  3.         double total = 0;
  4.         if (parts.length > 1) {
  5.             for(int i = 1; i < parts.length; i++) {
  6.                 if (i % 2 != 0) {
  7.                     String temp = parts[i];
  8.                     try {
  9.                         double val = Double.parseDouble(temp);
  10.                         total += val;
  11.                     } catch(NumberFormatException e) {
  12.                         e.printStackTrace(); // Not a number...
  13.                     }
  14.                 }
  15.             }
  16.         }
  17.         double mean = (total == 0 ? 0 : total / (parts.length / 2));
  18.         System.out.println(mean);
Advertisement
Add Comment
Please, Sign In to add comment