import java.io.*;
public class TestStringBuffer01
{
public static void main(String args[])throws IOException
{
BufferedReader buf;
String s1;
buf =new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入字符串:");
s1=buf.readLine();
StringBuffer sb1=new StringBuffer(s1);
StringBuffer sb2=sb1.reverse();
//System.out.println(sb1);
//System.out.println(sb2);
System.out.print("s1是否为回文:"+s1.equals(sb2.toString()));//这里的比较,sb2为什么要加toString啊?因为它是StringBuilder类型吗?
}
}
不是很懂哎!!!求指点......
public class TestStringBuffer01
{
public static void main(String args[])throws IOException
{
BufferedReader buf;
String s1;
buf =new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入字符串:");
s1=buf.readLine();
StringBuffer sb1=new StringBuffer(s1);
StringBuffer sb2=sb1.reverse();
//System.out.println(sb1);
//System.out.println(sb2);
System.out.print("s1是否为回文:"+s1.equals(sb2.toString()));//这里的比较,sb2为什么要加toString啊?因为它是StringBuilder类型吗?
}
}
不是很懂哎!!!求指点......
解决方案 »
- 用java模糊查询数据库数据时有个问题?
- Java问题
- 关于java中关于sql语句的问题……
- 关于PrepareStatment 中插入DATE的问题
- 在网页上显示用户客户端的硬盘信息??
- <script language="javascript" src="/tree/mztreeview10.js"></script>这句话是什么意思啊!
- BufferedInputStream的问题
- 那位大哥有sun.net.ftp 的技术文档…………?
- IO输出的行号问题!!!望大家帮忙解决!
- java编译器
- FileInputStream的read(byte[] b) 问题。。
- BigDecimal divide(BigDecimal divisor, int scale, int roundingMode) 方法
Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
也就是说:将此字符串与指定的对象比较。当且仅当该参数不为 null,并且是与此对象表示相同字符序列的 String 对象时,结果才为 true。
StringBuilder与String类型都不同,比较的话肯定返回false,所以要先把StringBuilder.toString()转换为String类型比较才有意思!