Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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";
- String[] parts = data.split(" ");
- double total = 0;
- if (parts.length > 1) {
- for(int i = 1; i < parts.length; i++) {
- if (i % 2 != 0) {
- String temp = parts[i];
- try {
- double val = Double.parseDouble(temp);
- total += val;
- } catch(NumberFormatException e) {
- e.printStackTrace(); // Not a number...
- }
- }
- }
- }
- double mean = (total == 0 ? 0 : total / (parts.length / 2));
- System.out.println(mean);
Advertisement
Add Comment
Please, Sign In to add comment