刚学java的小白想问个关于读取键盘输入数字的问题
import java.util.*;
public class Main {
public static void main(String[] args) {
Main main= new Main();
Menu start = new Menu();
main.checkId();
System.out.println("欢迎。。");
Scanner sc = new Scanner(System.in);
int select = sc.nextInt();
switch(select) {
case 1:;
}
}
//检查登录
private void checkId() {
//用来读取输入
Scanner input = new Scanner(System.in);
Boolean loginStatus = false;
//记录密码错误次数
int count = 0;
while(loginStatus == false) {
if(count >= 3) {
System.out.println("错误超过三次,账号冻结");
System.exit(-1);
}
System.out.println("请输入账号:");
String name = input.next();
System.out.println("请输入密码:");
String password = input.next();
if("admin".equals(name) && "admin".equals(password)) {
loginStatus = true;
//记得关闭扫描器
input.close();
System.out.println("登录成功");
break;
} else {
System.out.println("账号或密码错误,请重新输入");
count++;
}
}
}
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)更多0
欢迎加入618237474,找群主私聊,送海量学习资料免费送