生成四位编码的循环 例如:0001 0002 0003 前面的0时不能少的,必须得有。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 for (int i = 1; i < 10000; i++) { String str = "000" + i; System.out.println(str.substring(str.length()-4)); } Random r = new Random();int n = r.nextInt(10);生成一个[0,9]之间的随机整数,第一个为0,那么第一个就不需要随机生成了,直接赋值 -_-!public static void main(String[] args) { for(int i=0;;i++) System.out.println(((10000+(i%=10000))+"").substring(1)); } JDK 1.5 及以上for(int i=1; i<10000; i++) {String str = String.format("%04d", i);System.out.println(str);}JDK 1.5 以下DecimalFormat df = new DecimalFormat("0000");for(int i=0; i<10000; i++) {String str = df.format(i);System.out.println(str);} public static void main(String[] args) { for(int i = 0;i < 10000;i++){ String result = ""; switch(new String("" + i).length()){ case 1 : result = "000" + i; break; case 2 : result = "00" + i; break; case 3 : result = "0" + i; break; default : result = "" + i; } System.out.println(result); } } to:zjf405 回一下帖居然从裤衩变星星了,吓我一跳啊,楼主你真是我的福星啊不是吧 在JTextField中怎么 显示当前系统时间呢 ?有什么函数? 一个计算矩形面积的程序,怎么会出错? 把Frame改成JFrame,为什么监听器就不好用了? 高分请教!在线等候 一个可能和字符集有关的问题 一个关于ultraedit打开 java 文件 没颜色的问题!!!! 各位高手请帮我一个忙吧!! 请教多态!!!!!!(80分) 怎样更改一个按钮的标签?怎样知道我按的按钮是哪一个?(答对结帖) 这段代码为什么会这样输出? 一个父子关系的接口设计 java编程问题!请前辈帮忙?
String str = "000" + i;
System.out.println(str.substring(str.length()-4));
}
int n = r.nextInt(10);
生成一个[0,9]之间的随机整数,第一个为0,那么第一个就不需要随机生成了,直接赋值
for(int i=0;;i++)
System.out.println(((10000+(i%=10000))+"").substring(1));
}
for(int i=1; i<10000; i++) {
String str = String.format("%04d", i);
System.out.println(str);
}JDK 1.5 以下
DecimalFormat df = new DecimalFormat("0000");
for(int i=0; i<10000; i++) {
String str = df.format(i);
System.out.println(str);
}
for(int i = 0;i < 10000;i++){
String result = "";
switch(new String("" + i).length()){
case 1 : result = "000" + i;
break;
case 2 : result = "00" + i;
break;
case 3 : result = "0" + i;
break;
default : result = "" + i;
}
System.out.println(result);
} }
回一下帖居然从裤衩变星星了,吓我一跳啊,楼主你真是我的福星啊不是吧