[20-04-30][Self-test 24]Java SecondMax

Posted mirai3usi9

tags:

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

 1 package test_5_1;
 2 
 3 public class SecondMax {
 4 
 5     public static void main(String[] args) {
 6 
 7         /** 给定一个整型数组,数组成员10个,求该数组中第二大的数的下标 */
 8         int[] numArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
 9         int[] copyNumArr = new int[numArr.length];
10         
11         for (int i = 0; i < copyNumArr.length; i++) {
12             copyNumArr[i] = numArr[i];
13         }
14         
15         
16         for (int i = 0; i < numArr.length - 1; i++) {
17             for (int j = i + 1; j < numArr.length; j++) {
18                 if (numArr[i] < numArr[j]) {
19                     int temp = numArr[i];
20                     numArr[i] = numArr[j];
21                     numArr[j] = temp;
22                 }
23             }
24         }
25         
26         for (int i = 0; i < numArr.length; i++) {
27             if (numArr[i] == copyNumArr[1]) {
28                 System.out.println("第二大的数下标为:" + i);
29                 return;
30             }
31         }
32         
33         
34     }
35 
36 }

 

结果如下:

第二大的数下标为:7

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

[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