StringBufferDemo(将一个数字字符串转换成逗号分隔的数字串)

package

practice2;

 

import

java.util.Scanner;

 

public

class StringBufferDemo {

 

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Please iput a series of numbers:");

String num = input.next();

StringBuffer sb = new StringBuffer(num);

for (int i = sb.length() - 3; i > 0; i = i - 3) {

sb.insert(i, ',');

}

 

System.out.println(sb);

 

}

 

}

posted @ 2016-10-11 15:17  mabelfdm  阅读(647)  评论(0编辑  收藏  举报