Scanner input = new Scanner (System.in);
System.out.println("Enter -1 to exit the program");
System.out.println("Enter the search key: ");
int searchkey = input.nextInt();
String exit = input.nextLine();
while (!exit.equals("exit"))
{
linear(array, searchkey);
binary(array,searchkey);
System.out.println();
System.out.println("Enter exit to end the program");
System.out.println("Enter the search key: ");
searchkey = input.nextInt();
exit = input.nextLine();
}
我收到 InputMismatch 异常。我知道这是因为searchkey
. 如何使用字符串退出程序?