Supplier接口练习之获取最大值
作者:互联网
public class SupplierTest { public static void main(String[] args) { //定义数组 int[] a = {10,20,33,12,99}; //调用方法获取最大值 int MaxValue = getMax(()->{ int Max = a[0]; for (int i = 1; i<a.length;i++){ if (a[i] > Max){ Max = a[i]; } } return Max; }); System.out.println("最大值是:"+MaxValue); } private static int getMax(Supplier<Integer> sup){ return sup.get(); } }
标签:int,Max,最大值,接口,getMax,static,Supplier 来源: https://www.cnblogs.com/pxy-1999/p/13055988.html