Home > Java > javaTutorial > Java gets the maximum and minimum value in a set of data

Java gets the maximum and minimum value in a set of data

高洛峰
Release: 2017-02-11 15:43:28
Original
1659 people have browsed it

Without further ado, please look at the code:

public static void main(String[] args) {
 int array[]={2,4,3,9,1,6,8,5,23};
 int max=array[0],min=array[0];
 for(int i=0;i<array.length;i++){
  if(array[i]>max){
   max=array[i];
  }
 }
 for(int i=0;i<array.length;i++){
  if(array[i]<min){
   min=array[i];
  }
 }
 System.out.println(max);
 System.out.println(min);
}
Copy after login

The above is the entire content of this article. I hope that the content of this article can bring some help to everyone’s study or work. At the same time I also hope to support the PHP Chinese website!

For more java related articles on obtaining the maximum and minimum values ​​in a set of data, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template