Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4. public static boolean isSorted(double[] data)
- {
- for (int i=1; i<data.length; i++)
- {
- if (data[i] < data[i-1])
- {
- return false;
- }
- }
- return true;
- }
- 6. public static void main(String[] args)
- {
- int[] a = {1,-2,4,-4,9,-6,16,-8,25,-10};
- double sumA = 0;
- int count = 0;
- for (int i = 0;i<a.length;i++)
- {
- sumA = sumA + a[i];
- count++;
- }
- double avg = (sumA/count);
- System.out.println("avg = "+ avg);
- double numerator = 0;
- for(int j = 0;j<a.length;j++)
- {
- numerator += Math.pow(a[j]-avg,2);
- System.out.println("num" + j + "= " + numerator);
- }
- double inRoot = numerator/(a.length-1);
- double end = Math.sqrt(inRoot);
- System.out.println(end);
- }
Advertisement
Add Comment
Please, Sign In to add comment