Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

.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 83

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

How would you assess the value of an approach like this?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago