Java设计实践课练习题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java设计实践课练习题相关的知识,希望对你有一定的参考价值。

技术分享

技术分享
 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设计实践课练习题的主要内容,如果未能解决你的问题,请参考以下文章

实践课__浮动练习7

实践课__浮动练习8

20179214《网络攻防实践》第二三周课下练习

Java面向对象--数据库练习题

Java学习开始

学习经验分享(最近听了一节Java公开课)