4.16
作者:互联网
//1.有10个评委打分,(去掉一个最高一个最低)求平均分。 package learn; public class day05 { public static void main(String[] args) { int[]a= {55,60,65,70,75,80,85,90,95,100}; int q=0; for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { int temp=0; if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; break; } } } a[0]=0; a[9]=0; for(int x=0;x<10;x++) { q=a[x]+q; } q=q/8; System.out.println("平均分是"+q); } }
//2.自学一下Java随机数,生成一个长度为10的随机数组(每个数的范围是0~99),排序后输出。 package learn; import java.util.Random; public class day05 { public static void main(String[] args) { Random s=new Random(); int i=s.nextInt(100); Random r=new Random(); for(int y=0;y<10;y++) { int j = r.nextInt(100); System.out.println(j); } } }
//3.制作彩票35选7程序。 (就是1~35随机生成7个不重复的数) package learn; import java.util.Random; public class day05 { public static void main(String[] args) { Random r = new Random(); int i=r.nextInt(35)+1; System.out.println("35选7号码为:"); for (int j = 0; j <7; j++) { int k = r.nextInt(35)+1; System.out.println(j); } } }
//4.定义一个长度为10的int数组(如果没有特殊说明,静态赋值动态赋值都可以),统计数组中的最大值、最小值、以及奇 数和偶数的个数 package learn; import java.util.Random; public class day05 { public static void main(String[] args) { int[] score = new int[10]; Random r = new Random(); for (int i = 0; i < score.length; i++) { score[i] = r.nextInt(100); } System.out.println("原数组为:"); for (int i = 0; i < score.length; i++) { System.out.println(score[i]); } for (int i = 0; i < score.length - 1; i++) { for (int j =0; j < score.length - 1 - i; j++) { if (score[j] > score[j + 1]) { int tmp = score[j]; score[j] = score[j + 1]; score[j + 1] = tmp; } } } int ji = 0, ou = 0; for (int i = 0; i < score.length; i++) { if (score[i] % 2 == 0) { ou++; } else { ji++; } } System.out.println("最小值为:" + score[0]); System.out.println("最大值为:" + score[score.length - 1]); System.out.println("奇数个数:" + ji); System.out.println("偶数个数:" + ou); } }
标签:4.16,int,Random,System,score,public,out 来源: https://www.cnblogs.com/xiaomoa/p/12711657.html