Question
i have a code in java that does a binary search on a given array to determine if a user input number exist in the
i have a code in java that does a binary search on a given array to determine if a user input number exist in the given array. I must reprompt the user if the number is not in the array to enter another number to determine if it is in the array. This is where i have trouble:in the last part of the code I use a while loop to reprompt but when i run the program and test it still loops that the number is not in the array even though it is. how do i solve this with out for loops or another array
.I'm sure its something super simple i just dont get it. this is the last part of my code; the last else statement works, its just reprompt if statementand while above that doesn't. And i have already coded the binary search.
67 if (foundIndex== -1) { 68 69 70 while (foundIndex-=-1) { //int numberSearch2; System. out.print ("This number does not exist."); System.out.print (" Enter a number: ") 72 numberSearch-Integer.parseInt (keyboard.nextLine ()); 1) 74 75 1 6 else t System.out.println ("This numberl is valid."): 78 79 e0 e1 e2 83Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started