java程序,将十进制的数转化成以逗号为分隔的字符串。例如1234567变成1,234,567
2013-09-16
展开全部
import java.text.*;
import java.io.*;
public class T2 {
public static void main(String[] args) throws Exception {
int a=1234567;
DecimalFormat df=new DecimalFormat(",###");
System.out.println(df.format(a));
}
}
用java的格式化功能就可以了.
import java.io.*;
public class T2 {
public static void main(String[] args) throws Exception {
int a=1234567;
DecimalFormat df=new DecimalFormat(",###");
System.out.println(df.format(a));
}
}
用java的格式化功能就可以了.
2013-09-16
展开全部
//手写代码,其中的逻辑自己领悟吧- -!
int num = 1234567890;
String getNum = "";
while(num/1000 > 0){
String a = "," + num%1000;
num = num /1000;
getNum = a + getNum;
}
getNum = num+getNum;
System.out.print(num + "=" + getNum);
int num = 1234567890;
String getNum = "";
while(num/1000 > 0){
String a = "," + num%1000;
num = num /1000;
getNum = a + getNum;
}
getNum = num+getNum;
System.out.print(num + "=" + getNum);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询