码迷,mamicode.com
首页 > 其他好文 > 详细

HW6.11

时间:2016-08-25 21:14:07      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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 }

 

HW6.11

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5808229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!