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!