备用 br.read() 被跳过。如何使它们对编译器可见?
Alternate br.read()'s are getting skipped. How to make them visible to the compiler?
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;
等等,直到最后所有偶数位置的阅读都被忽略,尽管打印了相应的问题。尝试过各种古怪的事情,现在我失去了希望,请帮助!
正如@Jim Garrison 所说,这是因为忘记了用户输入的 newline
(enter) 个字符。
解决替换
(char)br.read();
有
(char)br.readLine().charAt(0);
charAt(index)函数在Javareturns相关String.Here0 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
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;
等等,直到最后所有偶数位置的阅读都被忽略,尽管打印了相应的问题。尝试过各种古怪的事情,现在我失去了希望,请帮助!
正如@Jim Garrison 所说,这是因为忘记了用户输入的 newline
(enter) 个字符。
解决替换
(char)br.read();
有
(char)br.readLine().charAt(0);
charAt(index)函数在Javareturns相关String.Here0 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