public class Ti { public static void main(String[] args){ int[] arrs1 ={12,22,32,42,52,62,72}; //冒泡排序 for (int i = 0; i < arrs1.length; i++) { for (int j = 0; j < arrs1.length - 1; j++) { if (arrs1[j] < arrs1[j + 1]) { int temp = arrs1[j + 1]; arrs1[j + 1] = arrs1[j]; arrs1[j] = temp; } } } p(arrs1); } public static void p(int[] arrs1) { for (int i = 0; i < arrs1.length; i++) { System.out.print(arrs1[i] + " "); } System.out.println("最大值~"+arrs1[0]); System.out.println("最小值~"+arrs1[6]); int a = arrs1[0]+arrs1[1]+arrs1[2]+arrs1[3]+arrs1[4]+arrs1[5]+arrs1[6]; System.out.println("和~"+a); double b = a/7; System.out.println("平均值~"+b); } }
public class Pai { public static void main(String[] args){ int[] arrs1 ={12,22,32,42,52,62,72}; //直接排序 for( int i=0; i<arrs1.length;i++){ int indexMax = i; for(int j=i + 1;j<arrs1.length;j++){ if(arrs1[indexMax] < arrs1[j]){ indexMax = j; } } int temp = arrs1[i]; arrs1[i] = arrs1[indexMax]; arrs1[indexMax] = temp; } p(arrs1); } public static void p(int[ ] arrs1) { for(int i=0;i<arrs1.length;i++){ System.out.println(arrs1[i]+" "); } System.out.println(); } }