// TestStringBuffer.java 主函数
package demo1;
public class TestStringBuffer {
public static void main(String[] args) {
// TODO Auto-generated method stub
TestBuff test = new TestBuff();
test.append("哈哈,");
}
}
// TestBuff.java构造函数
package demo1;
class TestBuff {
public void append (String str) {
StringBuffer strbuff = new StringBuffer(str);
strbuff.append("大家好");
System.out.println("拼接后:" + strbuff);
this.reverse(strbuff);
}
public void reverse (StringBuffer str) {
StringBuffer strbuff = new StringBuffer (str);
strbuff.reverse();
System.out.println("反转后:" + strbuff);
}
}
执行结果
网友评论