import java.util.Scanner;
Public class BinarySearch {
Public static void main (String args []) {
Scanner sc=new Scanner(System.in);
Int startN=sc. NextInt ();
Int endN=sc. NextInt ();
Int search=(int) (Math. The random () * (endN startN + 1) + startN);
Int l=endN startN + 1;
Int [] array=new int [l];
for(int i=0; I
StartN++;
}
Int the end=l - 1, start=0, middle=0;
Boolean found=false;
Int time=1;
While (start
If (array (middle) & gt; Search) {
End=middle - 1;
Time++;
} else if (array (middle) & lt; Search) {
Start=middle + 1;
Time++;
} else {
If (time> 1) {
System. Out.println (" The number is: "+" \ n "search + +" It took "+ time +" tries!" );
Found=true;
} else {
System. Out.println (" The number is: "+" \ n "search + +" It took "+ time +" try!" );
Found=true;
}
}
}
}
}
CodePudding user response:
The