LAI SHUN KEAT :
I have no idea why my scanner for the staffID and staffPassword is not working after I choose to continue typing a new record.
Click to see the output of the code
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);
}
}
parham damavandi :
use input.next()
instead of input.nextLine()
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=417681&siteId=1