package Test; public class Test { //Use the smallest memory to find if this number exists in the array 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("存在"); }else { System.out.println("Does not exist"); } System.out.println("=========================="); Test t = new Test(); t.paixu(arr, 29); } //Use the binary method to find if this number exists in this array public int peace (int [] arr, int x) { System.out.println(arr); int min = 0; int max = arr.length -1; while(min<=max) { int middle = (min + max)/2; if(x == arr[middle]) { return middle;//Return the subscript }else if(x < arr[middle]) { max = middle-1; }else { max = middle+1; } } return -1; } }