4.16上机

1.有10个评委打分,(去掉一个最高一个最低)求平均分。

 1 package pro1;
 2 
 3 import java.util.*;
 4 
 5 public class test {
 6     public static void main(String[] args) {
 7         int a[] = new int[10];
 8         int sum = 0, max = 0, min = 1000;
 9         System.out.println("请输入分数");
10         for (int i = 0; i < a.length; i++) {
11             Scanner input = new Scanner(System.in);
12             a[i] = input.nextInt();
13         }
14         for (int j = 0; j < a.length; j++) {
15             if (a[j] > max) {
16                 max = a[j];
17             }
18         }
19         for (int x = 0; x < a.length; x++) {
20             if (a[x] < min) {
21                 min = a[x];
22             }
23         }
24         for (int y = 0; y < a.length; y++) {
25             sum += a[y];
26         }
27         System.out.println("平均分为" + (sum - max - min) / 8.0);
28     }
29 }

 


2.自学一下Java随机数,生成一个长度为10的随机数组(每个数的范围是0~99),排序后输出。

{45,88,72,32,}

 1 package pro1;
 2 
 3 import java.util.Random;
 4 import java.util.*;
 5 
 6 public class test {
 7     public static void main(String[] args) {
 8         int a[] = new int[10];
 9         Random b = new Random();
10         for (int i = 0; i < a.length; i++) {
11             a[i] = b.nextInt(100);
12         }
13         for (int i = 0; i < a.length - 1; i++) {
14             for (int n = 0; n < a.length - 1 - i; n++) {
15                 if (a[n] > a[n + 1]) {
16                     int c = a[n];
17                     a[n] = a[n + 1];
18                     a[n + 1] = c;
19                 }
20             }
21 
22         }
23         for (int x = 0; x < a.length; x++) {
24             System.out.println(a[x]);
25         }
26     }
27 }

 



3.制作彩票35选7程序。 (就是1~35随机生成7个不重复的数)

 1 package pro1;
 2 
 3 import java.util.Random;
 4 import java.util.*;
 5 
 6 public class test {
 7     public static void main(String[] args) {
 8         int a[] = new int[7];
 9         Random b = new Random();
10         for (int i = 0; i < a.length; i++) {
11             a[i] = b.nextInt(35) + 1;
12         }
13         for (int x = 0; x < a.length; x++) {
14             System.out.println(a[x]);
15         }
16 
17     }
18 }

 

4.定义一个长度为10的int数组(如果没有特殊说明,静态赋值动态赋值都可以),统计数组中的最大值、最小值、以及奇 数和偶数的个数

 1 package pro1;
 2 
 3 import java.util.Random;
 4 import java.util.*;
 5 
 6 public class test {
 7     public static void main(String[] args) {
 8         int a[] = { 10, 20, 33, 34, 87, 90, 88, 9, 38, 44 }, q = 0;
 9         int o = 0, max = a[0], min = a[0];
10         for (int i = 0; i < a.length; i++) {
11             if (a[i] % 2 == 0) {
12                 o = o + 1;
13             } else {
14                 q = q + 1;
15             }
16         }
17         for (int x = 0; x < a.length; x++) {
18             if (a[x] > max) {
19                 max = a[x];
20             }
21         }
22         for (int y = 0; y < a.length; y++) {
23             if (a[y] < min) {
24                 min = a[y];
25             }
26         }
27         System.out.println("最大值是" + max + ",最小值是" + min + ",奇数有" + q + "个,偶数有" + o + "个");
28     }
29 }

 

posted @ 2020-04-16 11:51  潘宇航  阅读(113)  评论(0编辑  收藏  举报