1 Package Hello;2Import java.util.*;3 4 Public classHello {5 Public Static voidMain (String args[]) {6 Double[] A = produce (10000);7 int[] B =Tongji (a);8 for(inte:b) {9System. out. Print (E +" ");Ten } OneSystem. out. println (); A DoubleExp =expect (a); -System. out. println (exp); - Doublef =Fangcha (exp, a); theSystem. out. println (f); - - } - Public Static Double[] Produce (intlength) { + Double[] A =New Double[length]; - for(inti =0; i < length; i++) { +A[i] = math.random () *2-1; A } at returnA; - } - Public Static int[] Tongji (Doublea[]) { - int[] B =New int[ -]; - for(inti =0; i < a.length; i++) { - for(intj =0; J < B.length; J + +) { in if(A[i] >-1+0.1* J && A[i] <-1+0.1* (j +1)) { -b[j]++; to } + } - } the returnb; * } $ Public Static DoubleExpectDoubleb[]) {Panax Notoginseng Doublesum =0; - for(inti =0; i < b.length; i++) { thesum = sum +B[i]; + } A DoubleExp = sum/10000; the returnexp; + } - Public Static DoubleFangcha (DoubleExpDoublea[]) { $ Doublesum =0; $ for(inti =0; i < a.length; i++) { -sum = sum + (A[i]-exp) * (A[i]-exp); - } the Doublef = math.sqrt (sum/10000); - returnF;Wuyi } the}
View Code
1 Package Hello;2Import java.util.*;3 4 Public classHello {5 Public Static voidMain (String args[]) {6 Double[] A = produce (10000);7 int[] B =Tongji (a);8 for(inte:b) {9System. out. Print (E +" ");Ten } OneSystem. out. println (); A DoubleExp =expect (a); -System. out. println (exp); - Doublef =Fangcha (exp, a); theSystem. out. println (f); - - } - Public Static Double[] Produce (intlength) { + Double[] A =New Double[length]; - for(inti =0; i < length; i++) { +A[i] =getnumrandom (); A } at returnA; - } - Public Static int[] Tongji (Doublea[]) { - int[] B =New int[ -]; - for(inti =0; i < a.length; i++) { - for(intj =0; J < B.length; J + +) { in if(A[i] >-6+0.6* J && A[i] <-6+0.6* (j +1)) { -b[j]++; to } + } - } the returnb; * } $ Public Static DoubleExpectDoubleb[]) {Panax Notoginseng Doublesum =0; - for(inti =0; i < b.length; i++) { thesum = sum +B[i]; + } A DoubleExp = sum/10000; the returnexp; + } - Public Static DoubleFangcha (DoubleExpDoublea[]) { $ Doublesum =0; $ for(inti =0; i < a.length; i++) { -sum = sum + (A[i]-exp) * (A[i]-exp); - } the Doublef = math.sqrt (sum/10000); - returnF;Wuyi } the Public Static DoubleGetnumrandom () { - Doublesum =0; Wu for(inti =0; I < A; i++) { -sum = sum +math.random (); About } $ returnSum-6; - } -}
View Code
Java Design Practice Lesson Exercises