Java中数组获取最大和最小值 谁践踏了优雅 2021-09-28 13:44 326阅读 0赞 Java中数组获取最大和最小值 方法: 通过使用Collection类的Collection.max()和Collection.min()方法来查找数组中的最大和最小值 代码: import java.util.Arrays; import java.util.Collections; public class ArrayMaxOrMin { public static void main(String[] args) { Integer[] numbers = {8,2,7,1,4,9,5}; int min = (int)Collections.min(Arrays.asList(numbers)); int max = (int)Collections.max(Arrays.asList(numbers)); System.out.println("最小值为:"+min); System.out.println("最大值为:"+max); } } 结果: ![Java中数组获取最大和最小值的结果][Java] [Java]: /images/20210923/8c22efd9759e4ce986b874b0fb669d0e.png
还没有评论,来说两句吧...