java - 运行 DO WHILE 循环后,扫描仪不工作
问题描述
在我选择继续输入新记录后,我不知道为什么我的 StaffID 和 StaffPassword 扫描仪无法正常工作。
public class Test {
public static void main(String args[]){
String staffID, staffPassword; //Staff Record Variable
int a = 0;
boolean validation;
Staff[] staff = new Staff[1000];
int staffCount = 0;
Scanner input = new Scanner(System.in);
do{
staff[staffCount] = new Staff();
System.out.print("Staff ID: ");
staffID = input.nextLine();
staff[staffCount].SetStaffID(staffID);
System.out.print("Password: ");
staffPassword = input.nextLine();
staff[staffCount].SetPassword(staffPassword);
System.out.println("\nEnter 1 to continue, enter 2 to stop.");
System.out.print("Continue to add more record?(1 or 0): " );
a = input.nextInt();
}while(a == 1);
}
}
解决方案
使用input.next()
而不是input.nextLine()
推荐阅读
- swift - 如何使用 SwiftUI 的 onDelete() 函数访问数组位置
- python - 用 OpenCV + Python 拼接四个图像
- swift - ScrollView 在关闭 ViewController 并调用 viewDidLoad 时不会重新加载
- python - 从网站抓取价格为零的问题
- python - 如何遍历 UnqLite 集合并提取数据
- flutter - 用于颤振的 Chopper 库时请求中的内容类型被覆盖
- vhdl - if 会产生其他支持吗?
- database - 如何对放置在 docker 容器中的 oracle DB 启用统一审计?
- python-3.x - 如何将数组的元素(例如整数)转换为数组,以便在 python 中获得额外的维度
- javascript - 检查一个数组是否包含另一个数组的任何元素并突出显示另一个数组中的元素 - React native