4-16上机练习
package hm_4_16_practice; import java.util.Arrays; import java.util.Scanner; /* * 评委打分 去掉最低分和最高分求平均数 */ public class test01 { public static void main(String[] args) { Scanner sca= new Scanner(System.in); System.out.println("输入分数:"); int [] a = new int [10]; for (int i = 0; i < a.length; i++) { a[i]= sca.nextInt(); } System.out.println(Arrays.toString(a)); //进行排序 for (int i = 0; i < a.length-1; i++) { for (int j = 0; j < a.length-i-1; j++) { if (a[j]>a[j+1]) { int b =a[j]; a[j]=a[j+1]; a[j+1]=b; } } } System.out.println(Arrays.toString(a)); //求平均值 int avg= 0; int sum=0; for (int i = 0; i < a.length; i++) { if (i==0&&i==a.length-1) { continue; } sum+=a[i]; } avg= sum/a.length-2; System.out.println(avg); } } package hm_4_16_practice; import java.util.Arrays; import java.util.Random; /* * 生成10个随机数0-99 排序输出 */ public class test02 { public static void main(String[] args) { Random r = new Random(); int []arr = new int[10]; for (int i = 0; i <arr.length ; i++) { arr[i]= r.nextInt(100); } for (int i = 0; i < arr.length-1; i++) { for (int j = 0; j < arr.length-1-i; j++) { if (arr[j]>arr[j+1]) { int a = arr[j]; arr[j]=arr[j+1]; arr[j+1]=a; } } } System.out.println(Arrays.toString(arr)); } } package hm_4_16_practice; import java.util.Arrays; import java.util.HashSet; /* * 彩票35选7 */ import java.util.Random; import java.util.Set; public class test03 { public static void main(String[] args) { Random r= new Random(); Set<Integer> set = new HashSet<>(); //给数组添加数字 boolean b = true; while (b) { //产生一个1-35的数 int num = r.nextInt(35)+1; set.add(num); if (set.size()>6) { b=false; } } System.out.println(set); Object[]arr = new Object [set.size()]; set.toArray(arr); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } package hm_4_16_practice; /* * 10个数求最大最小值和 技术偶数个数 */ import java.util.Arrays; import java.util.Random; public class test04 { public static void main(String[] args) { Random r= new Random(); int [] arr= new int[10]; for (int i = 0; i < arr.length; i++) { arr[i]=r.nextInt(50)+20; } System.out.println(Arrays.toString(arr)); //求最大最小 奇数偶数个数 int jishu =0; int oushu = 0; int max=arr[0]; int min=arr[0]; for (int i = 0; i < arr.length; i++) { if (arr[i]%2==0) { oushu++; }else{ jishu++; } if (max<arr[i]) { max=arr[i]; }else{ min=arr[i]; } } System.out.println(max); System.out.println(min); System.out.println(jishu); System.out.println(oushu); } }