码迷,mamicode.com
首页 > 编程语言 > 详细

Java设计实践课练习题

时间:2017-05-24 12:42:28      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:gif   实践   ima   sed   ack   code   ide   sys   exp   

技术分享

技术分享
 1 package hello;
 2 import java.util.*;
 3 
 4 public class Hello {
 5     public static void main(String args[]){
 6         double[] a = produce(10000);
 7         int[] b = tongJi(a);
 8         for (int e : b) {
 9             System.out.print(e +" ");
10         }
11         System.out.println();
12         double exp = expect(a);
13         System.out.println(exp);
14         double f = fangCha(exp, a);
15         System.out.println(f);
16         
17     }
18     public static double[] produce(int length) {
19         double[] a = new double[length];
20         for (int i = 0; i < length; i++) {
21             a[i] = Math.random() * 2 - 1;
22         }
23         return a;
24     }
25     public static int[] tongJi(double a[]) {
26         int[] b = new int[20];
27         for (int i = 0; i < a.length; i++) {
28             for (int j = 0; j < b.length; j++) {
29                 if (a[i] > -1 + 0.1 * j && a[i] < -1 + 0.1 * (j + 1)) {
30                     b[j]++;
31                 }
32             }
33         }
34         return b;
35     }
36     public static double expect(double b[]) {
37         double sum = 0;
38         for (int i = 0; i < b.length; i++) {
39             sum = sum + b[i];
40         }
41         double exp = sum/10000;
42         return exp;
43     }
44     public static double fangCha(double exp, double a[]) {
45         double sum = 0;
46         for (int i = 0; i < a.length; i++) {
47             sum = sum + (a[i] - exp) * (a[i] - exp);
48         }
49         double f = Math.sqrt(sum/10000);
50         return f;
51     }
52 }
View Code

技术分享

技术分享
 1 package hello;
 2 import java.util.*;
 3 
 4 public class Hello {
 5     public static void main(String args[]){
 6         double[] a = produce(10000);
 7         int[] b = tongJi(a);
 8         for (int e : b) {
 9             System.out.print(e +" ");
10         }
11         System.out.println();
12         double exp = expect(a);
13         System.out.println(exp);
14         double f = fangCha(exp, a);
15         System.out.println(f);
16         
17     }
18     public static double[] produce(int length) {
19         double[] a = new double[length];
20         for (int i = 0; i < length; i++) {
21             a[i] = getNumRandom();
22         }
23         return a;
24     }
25     public static int[] tongJi(double a[]) {
26         int[] b = new int[20];
27         for (int i = 0; i < a.length; i++) {
28             for (int j = 0; j < b.length; j++) {
29                 if (a[i] > -6 + 0.6 * j && a[i] < -6 + 0.6 * (j + 1)) {
30                     b[j]++;
31                 }
32             }
33         }
34         return b;
35     }
36     public static double expect(double b[]) {
37         double sum = 0;
38         for (int i = 0; i < b.length; i++) {
39             sum = sum + b[i];
40         }
41         double exp = sum/10000;
42         return exp;
43     }
44     public static double fangCha(double exp, double a[]) {
45         double sum = 0;
46         for (int i = 0; i < a.length; i++) {
47             sum = sum + (a[i] - exp) * (a[i] - exp);
48         }
49         double f = Math.sqrt(sum/10000);
50         return f;
51     }
52     public static double getNumRandom() {
53         double sum = 0;
54         for (int i = 0 ; i < 12; i++) {
55             sum = sum + Math.random();
56         }
57         return sum - 6;
58     }
59 }
View Code

 

Java设计实践课练习题

标签:gif   实践   ima   sed   ack   code   ide   sys   exp   

原文地址:http://www.cnblogs.com/muziyueyueniao/p/6897833.html

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