首页 > 解决方案 > 运行 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);
    }
}

标签: java

解决方案


使用input.next()而不是input.nextLine()


推荐阅读