Home>Article>Java> How to implement the minimum value in an array in java

How to implement the minimum value in an array in java

王林
王林 forward
2020-04-13 17:33:15 5184browse

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); }

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
      

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
      

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete