因此,编译器一直说“输入”永远不会关闭。但是,程序运行并执行。我只是想知道为什么一直这么说。这是语法。提前谢谢。
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);
}
}
}
答案 0 :(得分:1)
这只是一个警告,遗憾的是不适用于你的情况,因为你真的不想关闭System.in
。
在该行之前添加@SuppressWarnings("resource")
(它也应该是快速修复)以消除警告。