Advertisement
Guest User

jm

a guest
Sep 29th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. public class cpk {
  2.  
  3. int a = 0;
  4. int count = 0;
  5. int total = 0;
  6. int total2 = 0;
  7. double average = 0;
  8. double r2 = 0;
  9. double sd = 0;
  10.  
  11. public cpk() {
  12. }
  13.  
  14. public void calculate(String s) {
  15. while (scanf("%d", & a) == 1) {
  16. total += a;
  17. total2 += a * a;
  18. count++;
  19. }
  20. if (count == 0) {
  21. System.out.println("No Input data");
  22. return;
  23. }
  24. average = total / count;
  25. System.out.println("Average value us %4.1f" + average);
  26. if (count == 1) {
  27. System.out.println("can calculate standard deviation with one data");
  28. return;
  29. }
  30.  
  31. r2 = total2 - 2 * average * total + average * count;
  32. sd = sqrt(r2 / (count - 1));
  33. System.out.println("Average value us %4.1f" + sd);
  34. return;
  35.  
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement