willieshi232

Untitled

Feb 25th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. 4. public static boolean isSorted(double[] data)
  2. {
  3. for (int i=1; i<data.length; i++)
  4. {
  5. if (data[i] < data[i-1])
  6. {
  7. return false;
  8. }
  9. }
  10. return true;
  11. }
  12.  
  13. 6. public static void main(String[] args)
  14. {
  15. int[] a = {1,-2,4,-4,9,-6,16,-8,25,-10};
  16. double sumA = 0;
  17. int count = 0;
  18. for (int i = 0;i<a.length;i++)
  19. {
  20. sumA = sumA + a[i];
  21. count++;
  22. }
  23. double avg = (sumA/count);
  24. System.out.println("avg = "+ avg);
  25.  
  26. double numerator = 0;
  27. for(int j = 0;j<a.length;j++)
  28. {
  29. numerator += Math.pow(a[j]-avg,2);
  30. System.out.println("num" + j + "= " + numerator);
  31. }
  32. double inRoot = numerator/(a.length-1);
  33. double end = Math.sqrt(inRoot);
  34. System.out.println(end);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment