- 问答
- 2019-04-11 11:52:50 @
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int daan = in.nextInt();
int zuixiao = 0;
int zuida = 1000;
int caishu = 500;
int cishu = 0;
while (caishu != daan) {
caishu = (zuixiao + zuida) / 2;
cishu = cishu + 1;
System.out.println("第" + cishu + "次:" + caishu);
if (caishu == daan) {
break;
} else if (caishu > daan) {
zuida = caishu;
} else if (caishu < daan) {
zuixiao = caishu;
}
}
}
}
1 条评论
-
lizilita LV 7 @ 2019-04-11 11:55:47
恰饭去了?
- 1