问题遇到的现象和发生背景
这里sc没有关闭,代码正常运行,但是一直有黄色的提示让我关闭sc
问题相关代码,请勿粘贴截图
import java.util.Scanner;
public class 用户登录 {
public static void main(String[] args) {
String username="1813436775";
String password="1813436775";
for(int i=0;i<3;i++){
Scanner sc = new Scanner(System.in);
System.out.println("请输入您的账号:");
String name=sc.nextLine();
System.out.println("请输入您的密码:");
String pwd=sc.nextLine();
if(name.equals(username) && pwd.equals(password)){
System.out.println("登陆成功!");
break;
}else{
if(2-i==0){
System.out.println("您的账户已被冻结,请联系管理员!");
}else{
System.out.println("登陆失败,您还有" + (2-i) + "次机会!");
}
}
}
}
}
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
如何能够消除提示并且系统正常运行