三行代码  ›  专栏  ›  技术社区  ›  Sandy Ketchum

替代的br.read()将被跳过。如何使它们对编译器可见?

  •  -1
  • Sandy Ketchum  · 技术社区  · 3 年前
        System.out.println("Q1.HOW DO YOU RECHARGE?");
        System.out.println("A. SPENDING TIME ALONE");
        System.out.println("B. PUBLIC DISCUSSIONS OR PARTIES");
        System.out.println("C. BOTH OF THEM ARE FINE IF I'M IN THE MOOD");
        char choice1 = (char)br.read();//this line gets executed perfectly fine
        if(choice1 == 'A')
        ct+=20;
        else if(choice1 == 'B')
        ct+=10;
        else
        ct+=30;
        System.out.println("Q2.ARE YOU OPEN TO NEW PEOPLE?");
        System.out.println("A. YES OF COURSE");
        System.out.println("B. I DON'T WANT TO TALK TO NEW PEOPLE");
        System.out.println("C. I CAN'T OPEN UP TO NEW PEOPLE UNTIL THEY ARE CLOSE ENOUGH");
        char choice2 = (char)br.read();//this one doesn't
        if(choice2 == 'A')
        ct+=10;
        else if(choice2 == 'B')
        ct+=20;
        else
        ct+=30;
        System.out.println("Q3.WOULD YOU GO FIRST OR LAST FOR A PRESENTATION?");
        System.out.println("A. I GUESS I WOULD GO FIRST ONLY IF I'M VERY CONFIDENT");
        System.out.println("B. OF COURSE FIRST!");
        System.out.println("C. NO. SO THAT I CAN LEARN FROM OTHER'S MISTAKES");
        char choice3 = (char)br.read();//this does
        if(choice3 == 'A')
        ct+=30;
        else if(choice3 == 'B')
        ct+=10;
        else
        ct+=20;
    

    这样,直到最后,即使打印出相应的问题,所有偶数位置的读数都会被忽略。尝试过各种奇怪的事情,现在我已经失去了希望,请帮忙!

    1 回复  |  直到 3 年前
        1
  •  0
  •   anoopknr    3 年前

    newline

    (char)br.read();
    

    (char)br.readLine().charAt(0);
    

    0 th

    char choice1 = (char)br.readLine().charAt(0); // Line 5
    char choice2 = (char)br.readLine().charAt(0); // Line 16
    char choice3 = (char)br.readLine().charAt(0); // Line 27