10/13
第一题:
1 package com.ben.www; 2 3 public class less01 { 4 public static void main(String[] args) { 5 int[] arr={411,420,53,6,7,2,27,57,74,110}; 6 7 for (int l = 0; l <arr.length-1 ; l++) { 8 for (int k = 0; k <arr.length-1 ; k++) { 9 if (arr[k]>arr[k+1]){ 10 int val2=arr[k]; 11 arr[k]=arr[k+1]; 12 arr[k+1]=val2; 13 } 14 } 15 } 16 17 System.out.println("数组元素如下:"); 18 for (int i1 = 0; i1 <arr.length ; i1++) { 19 System.out.println(arr[i1]); 20 } 21 22 23 System.out.println("最小值:"+arr[0]); 24 System.out.println("最大值:"+arr[arr.length-1]); 25 System.out.println("第二大值"+arr[arr.length-2]); 26 27 28 } 29 }
第二题:
1 package com.ben.www; 2 3 public class less02 { 4 5 6 public static int met (int[] arr){ 7 int val=0; 8 for (int i = 0; i < arr.length; i++) { 9 val+=arr[i]; 10 } 11 int aver=val/arr.length; 12 return aver; 13 } 14 15 public static void main(String[] args) { 16 int[] arr={12,43,62,74,263,737,84,26,83,37}; 17 for (int i = 0; i <arr.length ; i++) { 18 if (arr[i]>met(arr)){ 19 System.out.println(arr[i]); 20 } 21 } 22 23 } 24 }
第三题:
package com.ben.www; public class less03 { public static void main(String[] args) { int[] arr={14,5,6,72,62}; int val=0; for (int i = 0; i <arr.length ; i++) { if (arr[i] < 10) { val=arr[i]; System.out.println(val); } } if (val == 0) { System.out.println("找到合适的数据"); } } }
第四题:
1 package com.ben.www; 2 3 public class less04 { 4 public static void main(String[] args) { 5 int[] arr={142,34,262,74,848,36,3,7,4}; 6 int sum=0; 7 for (int i = 0; i <arr.length ; i++) { 8 sum+=arr[i]; 9 } 10 int aver=sum/arr.length; 11 int fre=0; 12 int[] arr1=new int[arr.length]; 13 int fre1=0; 14 15 for (int i=0; i <arr.length ; i++) { 16 if (arr[i] > aver) { 17 arr1[fre1]=arr[i]; 18 fre1++; 19 fre++; 20 } 21 22 } 23 System.out.println("大于平均值的元素的个数是:"+fre); 24 System.out.println("大于平均值元素的值分别是:"); 25 for (int i = 0; i <arr1.length ; i++) { 26 if (arr1[i] != 0) { 27 System.out.println(arr1[i]); 28 } 29 } 30 int sum1=0; 31 for (int i = 0; i <arr1.length ; i++) { 32 sum1+=arr1[i]; 33 } 34 System.out.println("大于平均数元素的和是:"+sum1); 35 36 } 37 38 39 }
第五题:
1 package com.ben.www; 2 3 public class less05 { 4 public static int[] met(int[]arr1,int[]arr2){ 5 int[] arr3=new int[arr1.length+arr2.length]; 6 for (int i = 0; i <arr1.length ; i++) { 7 arr3[i]=arr1[i]; 8 } 9 10 for (int i = 0; i < arr2.length; i++) { 11 arr3[i+arr1.length]=arr2[i]; 12 } 13 14 return arr3; 15 } 16 17 public static void main(String[] args) { 18 int[] arr1 = {1,2,3}; 19 int[] arr2 = {4,5,6}; 20 int[] acc_arr3=met(arr1,arr2); 21 for (int i = 0; i <acc_arr3.length ; i++) { 22 System.out.println(acc_arr3[i]); 23 } 24 } 25 }
第六题:
1 package com.ben.www; 2 3 public class less06 { 4 public static void main(String[] args) { 5 int[] arr={171,72,19,16,118,51,210,7,18}; 6 int sum=0; 7 for (int i = 0; i <arr.length ; i++) { 8 if (arr[i]%2==0&&arr[i]%10!=7&&arr[i]/100/10!=7&&arr[i]/10!=7) { 9 sum+=arr[i]; 10 11 } 12 } 13 System.out.println("满足要求的元素和是:"+sum); 14 } 15 }