StringBuffer .insert方法输出电话号码格式

package ch11;

import java.util.Scanner;

/**
* Created by liwenj on 2017/7/21.
*/
public class T7 {
public static void main(String[] args) {
String sz="13438377536";
StringBuffer sb=new StringBuffer(sz);
int len=sb.length();
int index=len-4;
while(true){
if (index>0){
sb.insert(index,"-");
index=index-4;
}else{
break;
}
}
System.out.println(sb);
}
}
posted @ 2017-07-21 17:07  斯丢皮德曼  阅读(313)  评论(0编辑  收藏  举报