Java中的字符比较
class Tryit {
public static void main(String args[])
throws java.io.IOException {
char ch, answer;
System.out.println("Please Enter a Secret Character for another user to guess.");
answer = (char) System.in.read();
System.out.println("There is a Secret character for you...Can you guess it: \n");
ch = (char) System.in.read(); // read a char from the keyboard
if(ch == answer)
{
System.out.println("** Right **");
}
else
{
System.out.println("** Try Again **");
}
}
}
我试图比较ch和answer变量,但它不起作用,我犯了错误。帮助
# 1 楼答案
使用扫描仪。。。这很容易
然后只需比较==,在循环时添加踢击