gpt4 book ai didi

java - 扫描仪的功能。关闭扫描仪会引起问题

转载 作者:行者123 更新时间:2023-12-01 18:10:08 25 4
gpt4 key购买 nike

I am getting flickering screen when closing the scanner,but without closing it works fine.

public void removeBranch() {
try {
Scanner input=new Scanner(System.in);
System.out.print("Enter branch id to remove:");
int Id=input.nextInt();
int toDelete=branchPresent(Id);
if(toDelete!=-1) {
branches.remove(toDelete);
System.out.println("Branch removed");
}else {
System.out.println("\n No such Branch!\n");
}
} catch (Exception e) {
System.out.println("\nsomething went wrong while removing !\n");
}

}

最佳答案

finally block 中关闭扫描仪

try{
Scanner input=new Scanner(System.in);
// Do stuff
}
catch {
// Handle exception
}
finally {
input.close();
}


关于java - 扫描仪的功能。关闭扫描仪会引起问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60481552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com