Randomly generate an array with a length of 100, with an array element ranging from 1 to 10. measure the number of occurrences and minimum number of elements.

Source: Internet
Author: User

The idea is simple. You can understand it at a glance.

Import Java. util. *; Class max {static int A, B, C, D, E, F, G, H, I, J; public static void main (string [] ARGs) {int [] num = new int [100]; random RD = new random (); For (INT n = 0; n <100; n ++) {num [N] = RD. nextint (10) + 1; system. out. println (Num [N]); If (Num [N] = 1) A ++; else if (Num [N] = 2) B ++; else if (Num [N] = 3) c ++; else if (Num [N] = 4) d ++; else if (Num [N] = 5) e ++; else if (Num [N] = 6) f ++; else if (Num [N] = 7) g ++; else if (Num [N] = 8) h ++; else if (Num [N] = 9) I ++; else if (Num [N] = 10) J ++;} int [] Cn = {, b, C, D, E, F, G, H, I, J}; arrays. sort (CN); system. out. println (arrays. tostring (CN); int max = count (CN [9]); int min = count (CN [0]); system. out. println ("the most frequently seen is:" + MAX + ", total:" + CN [9] + "," + "the least appears: "+ min +", total: "+ CN [0] +" Times, ");} static int count (INT m) {If (M =) return 1; else if (M = B) return 2; else if (M = c) Return 3; else if (M = d) return 4; else if (M = e) return 5; else if (M = f) return 6; else if (M = g) return 7; else if (M = h) return 8; else if (M = I) return 9; else if (M = J) return 10; elsereturn 0 ;}}

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.