请进
import java.io.*;
public class Teststr
{
public static void main ( String [ ] args ) throws IOException
{
String str1,str2;
char [ ] strArr = new char [ 10 ];
byte [ ] buff = new byte [ 10 ];
System.out.print ( "Input a string: " );
System.in.read ( buff, 0, 10 );
str1 = new String ( buff );
System.out.print ( "The string is : " + str1 );
// 反向输出字符串
for ( int i = str1.length ( ) - 1; i >= 0; i-- )
{
strArr [ str1.length ( ) - 1 - i ] = str1.charAt ( i ) ;
}
str2 = new String ( strArr );
System.out.println ( "The other string is : " + str2 );
//回文判断
if ( ( str2.compareTo ( str1 ) ) == 0 )
{
System.out.print ( "是回文" );
}
else
{
System.out.print ( "不是回文" );
}
}
}
例如我输入“12321”,反相也输出“12321”,但是在字符串比较上总是不相等,用equals或者
equalsIgnoreCase方法,总是得出不相等的结果,为什么呢,要怎样修改?