整除数组 外部设置处理打印 max package 数组; public class max1 { public static void main(String[] args){ int[] arr1= {33,5,22,55,44}; int max=arr1[0];//不能等于0 for (int i =1;i<= arr1.length;i++){ if(arr1[i]>max){ max=arr1[i]; System.out.println("最大值是"+max); } } } }
符合二元一次方程的数组可以if里面直接处理数组
package 数组; public class max1 { public static void main(String[] args){ int[] arr1= {33,5,22,55,44}; int max=arr1[0];//不能等于0 for (int i =1;i<= arr1.length;i++){ if(arr1[i]>=arr1[i-1]&&arr1[i]>=arr1[i+1]){ System.out.println("最大值是"+arr1[i]); } } } }