读心术的那个我次数也设了,为啥还是不对,第七个案例

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

public class Main3 {
    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 shishu = in.nextInt();
        int caishu = 0;
        int zhuida = 1000;
        int zhuidi = 1;
        int cishu = 0;
        int cs = 10;
        while (caishu != shishu) {
            if (caishu > shishu) {
                zhuida = caishu;
                caishu = (zhuida + zhuidi) / 2;
                cs=cs-1;
                cishu=cishu+1;
                ps.println("第"+cishu+"次:"+caishu);
            }
            if (caishu < shishu) {
                zhuidi = caishu;
                caishu = (zhuida + zhuidi) / 2;
                cishu=cishu+1;
                cs=cs-1;
                ps.println("第"+cishu+"次:"+caishu);
            }
            if(cs==0)
            {
                break;
            }
            
        }
    }
}

1 条评论

  • 1