标签:
1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 double[] number = new double[10]; 9 System.out.print("Enter ten numbers: "); 10 for(int i = 0; i < 10; i++) 11 number[i] = input.nextDouble(); 12 13 input.close(); 14 15 System.out.println("The mean is " + mean(number)); 16 System.out.println("The deviation is " + deviation(number)); 17 } 18 19 public static double mean(double[] array) 20 { 21 double sum = 0; 22 for(double i: array) 23 sum += i; 24 return sum / array.length; 25 } 26 27 public static double deviation(double[] array) 28 { 29 double squareSub = 0; 30 for(double i: array) 31 squareSub += (mean(array) - i) * (mean(array) - i); 32 return squareSub / (array.length - 1); 33 } 34 }
标签:
原文地址:http://www.cnblogs.com/wood-python/p/5808229.html