java 二分查找

it2023-02-05  48

package sai.company.lesson3;

import java.util.Arrays;

public class TwoFEN { public static void main(String[] args) {

int[] test={12,345,3434,65,5,343,3,454,6,5,434,7,4,35,343,34,543,1,54,1,76,5467,1,4567}; int[] sortTest=sort(test); int testNum=5467;//需要查找的目标 System.out.println(Arrays.toString(sortTest));//先整列 System.out.println(erfentansuo(testNum,sortTest)); } public static int[] sort(int[] obj){ int tmp; for (int i = 0; i <obj.length-1 ; i++) { for (int j = 0; j <obj.length-1-i ; j++) { if(obj[j]>obj[j+1]){ tmp=obj[j]; obj[j]=obj[j+1]; obj[j+1]=tmp; } } } return obj; } public static String erfentansuo(int a,int[]b){ int low=0; int hi=b.length-1; String msg1="目标不存在"; String msg2="目标存在";
最新回复(0)