System.out.println("-----------------------------------------------------------");
System.out.println("Please select a task");
System.out.println("1: List employees with details");
System.out.println("2: List of clients in state");
System.out.println("3: List portfolio of client");
System.out.println("4: Release an employee");
System.out.println("5 Display stocks available for purchase/selling");
System.out.println("6: Display client details");
System.out.println("7: Buy Stock for client ");
System.out.println("0: Exit program");
System.out.println("-----------------------------------------------------------" + "\n" + "\n");
System.out.print("Input:");
Scanner scan = new Scanner(System.in);
input = scan.nextInt();
if (input == 1)
{
System.out.println("length of array list: " + employeeList.size());
int index = 0;
while ( index < employeeList.size() )
{
System.out.println(employeeList.get(index));
index++;
}
}
else if (input == 2)
{
String state_choice;
System.out.println("Please enter the abbrivation for the state:");
state_choice = scan.nextLine();
This is a portion from my current code I’m having issues at [else if (input == 2)] when I try to run it doesn’t let me input and just ignores it actually. I think its because of the “\n” from the previous entry. Is there a way to remove that “\n” or extra character without putting another scan.nextLine() before my entry? Didn’t really see anything in java docs..
Just add
scan.nextLine();afterinput = scan.nextInt();. The problem is withininput = scan.nextInt();, it only reads integer number, so you needscan.nextLine();to discard the new line\ngenerated by pressing Enter.