[20-04-30][Self-test 25]Java MaxAndMin

Posted mirai3usi9

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[20-04-30][Self-test 25]Java MaxAndMin相关的知识,希望对你有一定的参考价值。

 1 package test_5_2;
 2 
 3 public class MaxAndMin {
 4 
 5     public static void main(String[] args) {
 6 
 7         /** 有10个分,去掉一个最高一个最低求平均分 */
 8         int[] numArr = {99, 97, 96, 95, 94, 92, 91, 90, 88, 100};
 9         
10         for (int i = 0; i < numArr.length; i++) {
11             numArr[i] = numArr[i];
12         }
13         
14         for (int i = 0; i < numArr.length - 1; i++) {
15             for (int j = i + 1; j < numArr.length; j++) {
16                 if (numArr[i] < numArr[j]) {
17                     int temp = numArr[i];
18                     numArr[i] = numArr[j];
19                     numArr[j] = temp;
20                 }
21             }
22         }
23         
24         int sum = 0;
25         for (int i = 1; i < numArr.length - 1; i++) {
26             sum += numArr[i];
27         }
28         
29         System.out.println("去掉最高最低分后平均分为:" + sum * 1.0 / (numArr.length - 2));
30         
31         
32     }
33 
34 }

 

结果如下:

去掉最高最低分后平均分为:94.25

以上是关于[20-04-30][Self-test 25]Java MaxAndMin的主要内容,如果未能解决你的问题,请参考以下文章

[20-04-26][Self-test 6]Java CharType

[20-05-09][Self-test 40]Java BankSystem 1

[20-05-09][Self-test 40]Java BankSystem 1

[20-06-04][Self-test 46]Java Linker Manage

[20-06-04][Self-test 46]Java Linker Manage

[20-05-02][Self-test 31]Java Dictionary