-4
因此,由於某種原因,編譯器總是說「輸入」從不關閉。但是,該程序運行並執行。我只是想知道爲什麼它一直說。這是語法。提前致謝。關於錯誤的誤解
import java.util.Scanner;
public class Problem1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter three numbers: ");
int N1 = input.nextInt();
int N2 = input.nextInt();
int N3 = input.nextInt();
DoSort(N1, N2, N3);
}
public static void DoSort(int N1, int N2, int N3){
if ((N1 < N2) && (N2 < N3)){
System.out.println("The acsending order is " + N1 + " " + N2 + " " + N3);
}
if ((N1 > N2) && (N2 > N3)){
System.out.println("The acsending order is " + N3 + " " + N2 + " " + N1);
}
if ((N1 < N2) && (N2 > N3) && (N1 < N3)){
System.out.println("The acsending order is " + N1 + " " + N3 + " " + N2);
}
if ((N1 < N2) && (N2 > N3) && (N1 > N3)){
System.out.println("The acsending order is " + N3 + " " + N1 + " " + N2);
}
}
}
因爲你沒有關閉它?在完成輸入後,可以使用input.close()關閉它。 – Janar
如果您使用的是JDK 7或更高版本,請嘗試類似'try(Scanner input = ....){//代碼塊}。 – SMA
注意:你的'DoSort'邏輯不考慮一些數字相同的情況。 –