StringBuffer .insert() .Append()方法

package leixifeng;

import java.util.Scanner;

public class Yanzheng {

    public static void main(String[] args) {
        
        Scanner input = new Scanner(System.in);
        System.out.println("请输入金额");
        String nums = input.next();
        StringBuffer str =new StringBuffer(nums);
        for(int i = str.length()-3; i > 0 ; i-=3){
            str.insert(i, ',');
        }
        System.out.println(str);
    }

}
//StringBuffer 字符串的连接效率比String类高

StringBuffer sb = new StringBuffer("青春无悔");
        int num = 110;
        StringBuffer sb1 = sb.append("我心永恒");        //小写append
        System.out.println(sb1);
        StringBuffer sb2 = sb1.append("啊");
        System.out.println(sb2);
        StringBuffer sb3 = sb2.append(num);
        System.out.println(sb3);

posted @ 2016-08-01 17:59  me丶不是好人  阅读(1109)  评论(0编辑  收藏  举报