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

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

高洛峰
高洛峰Original
2017-02-11 15:43:281599browse

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

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!


Statement:
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