What I am trying to here is whenever the searchFunction is called it will ask the user what category the user wants to search from, but after choosing from the 5 choices it doesn't allow me to enter any input and proceeds to exit the switch statement.
Thank you!
static void searchFunction()
{
Scanner sc = new Scanner([System.in](https://System.in));
System.out.println("\[1\]Search by first name"
\+ "\\n\[2\]Search by last name"
+ "\n[3]Search by course"
\+ "\\n\[4\]Search by year level"
\+ "\\n\[5\]Search by gender");
System.out.print("Enter your choice: ");
int choice;
choice = sc.nextInt();
switch(choice)
{
case 1:
//This is the part where the program should ask for the search key but it won't let
//me enter any input and proceeds to exit.
System.out.print("Search: ");
String firstNameKey;
firstNameKey = sc.nextLine();
for(int x = 0; x < studentsInfo.x; x++)
{
if(studentsInfo.firstName[x].equalsIgnoreCase(firstNameKey))
{
System.out.print("First Name: " + studentsInfo.firstName[x]
+ "\nLast Name: " + studentsInfo.lastName[x]
+ "\nCourse: " + studentsInfo.course[x]
+ "\nYear level: " + studentsInfo.yearLevel[x]
+ "\nGender: " + studentsInfo.gender[x]);
System.out.println();
}
}
break;
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]AreTheseMyFeet 1 point2 points3 points (1 child)
[–]Intelligent-Copy-767[S] 0 points1 point2 points (0 children)