Java?????????????
???????????? ???????[ 2014/3/5 10:55:02 ] ????????Java ?????????
??????????????
import java.util.Scanner;
//?????
public class SplitBy2Sort {
public static int splitBy2(int[] a?? int num) {
int low = 0;
int high = a.length - 1;
int mid;
while (true) {
// ??м??±?
mid = (low + high) / 2;
if (a[mid] == num) {
return mid;
} else if (low > high) {
return -1;
} else if (num > a[mid]) {
low = mid + 1;
System.out.println("?±???????");
} else if (num < a[mid]) {
high = mid - 1;
System.out.println("?±???????");
}
}
}
public static void main(String[] args) {
int[] a = { 1?? 3?? 6?? 12?? 26?? 37?? 47?? 58?? 69?? 78?? 80?? 98?? 100?? 114?? 126??137?? 146?? 155?? 164?? 173 };
System.out.println("???????????");
for (int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
System.out.println("???????????????");
Scanner s = new Scanner(System.in);
int num = s.nextInt();
int index = splitBy2(a?? num);
if (index != -1) {
System.out.println("?????±????" + index);
} else {
System.out.println("????????????");
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11