4.16 on-board

1. There are 10 judges to score, (remove one highest and one lowest) to get the average score.

 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. Learn about Java random numbers by yourself, generate a random array of length 10 (each number ranges from 0 to 99), and output after sorting.

{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. Make 7 out of 35 lottery programs. (That is, 1 ~ 35 randomly generates 7 non-repeating numbers)

 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. Define an int array of length 10 (if there is no special instruction, static assignment and dynamic assignment can be used), statistics of the maximum and minimum values ​​in the array, and the number of odd and even numbers

 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 ("The maximum value is" + max + ", the minimum value is" + min + ", odd number has" + q + ", even number has" + o + "number" );
 28      }
 29 }

 

Guess you like

Origin www.cnblogs.com/qq1123514689/p/12711721.html