{System.out.println(str+ " is not symmetrical!");}
else
System.out.println(str + " is symmetrical");
}
public static void main(String[] args) throws Exception{
/*Scanner in = new Scanner(System.in);
String str = in.next();*/
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
String str = null;
while((str = bufr.readLine())!= null)
{
if("over".equals(str))
break;
// System.out.println(line);
isSymmetrical(str);
}
bufr.close();
}
}
复制代码
输出:
asd
asd is not symmetrical!
asa
asa is not symmetrical!
但是在boolean flag = (string1.equals(str));
改为:boolean flag = ((string1.toString()).equals(str.toString()));
问题就没有了...这到底是为什么?我测试了,输入的制确实被反转了,但为什么比较出来永远是false?