数组-倒转(for多条件)+查找最大值
作者:互联网
package com.fh.base; public class T { public static void main(String[] args) { int[] array = new int[10]; for (int i = 0; i < array.length; i++) { array[i] = i+1; } int[] reverse = reverse(array); System.out.println("倒转数组:"); printArray(reverse); System.out.println("数组最大值:" + max(array)); } /** * 打印数组 */ public static void printArray(int[] array){ for (int i = 0; i < array.length; i++) { System.out.println(array[i]); } } /** * 倒转数组 */ public static int[] reverse(int[] array){ int[] result = new int[10]; for (int i = 0,j=array.length-1; i < array.length; i++,j--) { result[j] = array[i]; } return result; } /** * 查找最大值 */ public static int max(int[] array){ int max = 0; max = array[0]; for (int i = 0; i < array.length; i++) { if(max < array[i]){ max = array[i]; } } return max; } }
标签:int,max,最大值,length,查找,static,倒转,array,public 来源: https://www.cnblogs.com/jzbl/p/16329072.html