/*
* 程序头部注释开始
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:StringBuffer的练习
* 作 者:薛广晨
* 完成日期:2012 年 10 月 10 日
* 版 本号:x1.0
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:
* 程序头部的注释结束
*/
class StringBufferTest
{
public static void main(String[] args)
{
//method_add();
//method_del();
//method_update();
//method_getChars();
draw(6, 4);
}
public static void method_add()
{
StringBuffer sb = new StringBuffer();
sb.append("abc").append(true).append(34);
sb.insert(1,"qq");
sop(sb.toString());
}
public static void method_del()
{
StringBuffer sb = new StringBuffer("abcdefg");
//sb.delete(1,4);
//清空缓冲区。
//sb.delete(0, sb.length());
//sb.delete(2,3);
sb.deleteCharAt(2);
sop(sb.toString());
}
public static void method_update()
{
StringBuffer sb = new StringBuffer("abcdefg");
//sb.replace(1, 3, "java");
sb.setCharAt(1,'m');
sop(sb.toString());
}
public static void method_getChars()
{
StringBuffer sb = new StringBuffer("abcdefg");
char[] chs = new char[6];
sb.getChars(1, 4, chs, 2);
for(int i = 0; i < chs.length; i++)
{
sop("chs["+i+"]=" + chs[i] + ";");
}
}
public static void draw(int row,int col)
{
StringBuilder sb = new StringBuilder();
for(int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
{
sb.append("*");
}
sb.append("\r\n");
}
sop(sb.toString());
}
public static void sop(String str)
{
System.out.println(str);
}
}
StringBuffer的练习
最新推荐文章于 2022-04-28 13:20:32 发布