Finding the max/min value in an array of primitives using Java

前端 未结 15 2077
遥遥无期
遥遥无期 2020-11-22 05:09

It\'s trivial to write a function to determine the min/max value in an array, such as:

/**
 * 
 * @param chars
 * @return the max value in the array of chars         


        
15条回答
  •  Happy的楠姐
    2020-11-22 05:25

    import java.util.Arrays;
    
    public class apples {
    
      public static void main(String[] args) {
        int a[] = {2,5,3,7,8};
        Arrays.sort(a);
    
         int min =a[0];
        System.out.println(min);
        int max= a[a.length-1];
        System.out.println(max);
    
      }
    
    }
    

提交回复
热议问题