package hello; public class Zuidazhi { public static void main(String[] args) { int[] a =new int[]{1,2,3,4,5,6}; int b=a[0]; System.out.println(a[0]); for(int j=0;j<a.length;j++){ if(b<a[j]) { b=a[j]; } } System.out.println("最大数是:"+b); } }
最小值:
package hello; public class zuixiaozhi { public static void main(String[] args) { int []a=new int[]{1,2,3,4,5,6}; int b=a[0]; for(int i=0;i<a.length;i++){ if(b>a[i]){ b=a[i];} } System.out.println(b); } }