Find the most value in the Java array

Source: Internet
Author: User

In the Java array to find the most value, which in the actual development of almost no use, but in the interview will occasionally be asked, this is the test of your basic thinking ability, now say the basic idea of the problem


Ideas:

1: First define a variable, usually with the first value of the array

2: Judge in the loop (the value from the second corner to the length-1 of the array) is greater than the previously defined value, and if it is greater then assign the value to max, and then you can find the maximum value


The code is as follows:

public static void Main (string[] args) {int[] arr = {1,3,5,6,9,7};int max = arr[0];for (int i=1;i<arr.length;i++) {if (arr [I]>max) {max = Arr[i];}}}


Find the most value in the Java array

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.