Java Design Practice Lesson Exercises

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.