简体   繁体   English

Java 数组排序帮助:如何在扫描仪上输入时执行此操作

[英]Java array sort help: How to execute this on inputting on scanners

inp1 = getinp1();
inp2 = getinp2();
inp3 = getinp3();
inp4 = getinp4();
inp5 = getinp5();

int[] numbers = {inp1,inp2,inp3,inp4,inp5};
Arrays.sort(numbers);

System.out.println("The highest number is "+numbers[2]);
System.out.println("The middle number is "+numbers[1]);
System.out.println("The lowest number is "+numbers[0]);

The output are showing only inp3, inp4 , inp5 but it must need to mix with other inputs so that it could make a right decision what is highest middle and smallest value输出只显示 inp3、inp4、inp5,但它必须与其他输入混合,以便它可以做出正确的决定什么是最高的中间值和最低值

As per the above Code the index which you have mentioned is wrong.根据上面的代码,您提到的索引是错误的。 It should be like below.它应该像下面这样。

    System.out.println("The highest number is "+numbers[numbers.length-1]);
    System.out.println("The middle number is "+numbers[2]);
    System.out.println("The lowest number is "+numbers[0]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM