[英]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]);
輸出只顯示 inp3、inp4、inp5,但它必須與其他輸入混合,以便它可以做出正確的決定什么是最高的中間值和最低值
根據上面的代碼,您提到的索引是錯誤的。 它應該像下面這樣。
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.