VScode中JAVA程序"Resource leak: ‘sc’ is never closed"问题解决
这可能带来一些安全问题,那么要怎么解决这个问题呢?既然‘sc’没有关闭,那么我们只需要把‘sc’关闭就好了,此时需要在后面添加’sc.close();’就解决。
修改后代码如下:
import java.util.*;
public class Print {
public static void main(String[] args) {
double num=0;;
Scanner sc=new Scanner(System.in);
num = sc.nextDouble();
sc.close();
if(num == 1){
System.out.println("1");
}
else{
System.out.println("0");
}
}
}