How to implement the minimum value in an array in java

王林
Release: 2020-04-13 17:33:15
forward
5063 people have browsed it

How to implement the minimum value in an array in java

Purpose:

First create an array with a length of 5, then assign a random integer to each bit of the array, and find the smallest (largest) value come out.

Method 1:

        int array[] = new int[5];
        System.out.println("数组的元素为:");
        for (int i=0;iarray[i]){
                min=array[i];
            }

        }
        System.out.println("方法二:最小值为:"+min);
    }
Copy after login

Result:

How to implement the minimum value in an array in java

## (Recommended tutorial:

java quick start)

Method 2:

        int array[] = new int[5];
        System.out.println("数组的元素为:");
        for (int i=0;i
Copy after login

Result:


How to implement the minimum value in an array in java##Method 3:

Collections through Collections class .max() and Collections.min() methods to find the maximum and minimum values ​​in an array.

The code is as follows:

        Integer array[] = new Integer[5];
        System.out.println("数组的元素为:");
        for (int i=0;i
Copy after login

Result:


## Recommended related video tutorials: How to implement the minimum value in an array in javajava video tutorial

The above is the detailed content of How to implement the minimum value in an array in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!