Here's the description of what I need to do for the assignment:

Write a program that creates an array of 1000 random numbers in the range 1 – 5000. Then ask the user for a value between and 5000, and search the array until you either find the value or determine that the value is not in the array. Print a message indicating whether or not the value was found, and how many numbers you had to look at before you found the value (or determined that it was not there).

The program I've written so far stops after one guess it needs to keep cycling until you guess the right number

here's my code so far:

does anyone have any ideas on what I could change around or fix with my codeCode:import java.util.*; public class FindNumber { final int MaxVal = 5000; int value; int numbers[] = new int[1000]; FindNumber() { Random rg = new Random(); for (int i=0;i<numbers.length;i++) numbers[i]=rg.nextInt(MaxVal+1); Arrays.sort(numbers); } public int searchValue(int val) { int min=0, max = numbers.length; int i=0; while(true) { i++; if (numbers[(max+min)/2]==val) return i; else if (val > numbers[(max+min)/2]) min = (max+min)/2 + 1; else max = (max+min)/2 - 1; if (min==max) return -1; } } public static void main(String[] args) { FindNumber fn = new FindNumber(); Scanner kb = new Scanner(System.in); System.out.println("Enter any positive integer between 1 and 5000."); int x = kb.nextInt(); if (fn.searchValue(x)>0) System.out.println("Found in " + fn.searchValue(x) + " tries."); else System.out.println("Value not found."); } }

Tweet This+ 1 thisPost To Linkedin