-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'逻辑不考虑一些数字相同的情况。 –