读心术为何少于十次猜出答案后还错

import java.util.Scanner;
import java.io.PrintStream;

public class Main {
    public static void main(String[] args) throws java.io.UnsupportedEncodingException {
        PrintStream ps = new PrintStream(System.out, true, "UTF-8");
        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 条评论

  • 1