Package Test;public class Test {//finds the array in the smallest memory with the number public static void main (string[] args) {int [] arr = {12,2,3,4,5,6,7,8 , 90,76,43};byte[] byt = new Byte[100];for (int i = 0; i < arr.length; i++) {byt[arr[i]] = 1;} int n = 13;if (Byt[n] = = 1) {System.out.println ("exists");} else {System.out.println ("does not Exist");} System.out.println ("=========================="); Test t = new Test (); T.paixu (arr, 29);} Find out in this array whether the number public int Paixu (int[] Arr,int x) {System.out.println (arr) is found in the binary method, int min = 0;int max = Arr.length-1;while (M In<=max) {int middle = (min + max)/2;if (x = = Arr[middle]) {return middle;//returns the subscript}else if (x < Arr[middle]) {max = mid Dle-1;} else {max = middle+1;}} return-1;}}
Find out if the number exists in the array with the smallest memory and binary method