- public class Max {
-
- public static void main(String[] args) {
- int[] a = new int[] {1,5,2,31,4,45,346,4,53,8,3,8,23};
- System.out.println(swapMax(a));
- }
-
- public static int swapMax(int[] array){
- int max = 0 ;
- for (int i = 1; i < array.length; i++) if(array[max]<array[i]) max = i ;
- return array[max];
- }
- }
复制代码 |