作者liu2007 (薯)
看板java
标题[问题] 为什麽他显示不出正确的流水号??
时间Sun Aug 16 20:21:40 2009
这是小弟第一次在夹肉版发文
请多多指教
下面是个小习题
是一个产生10万份身分证字号的程式
共十码
第一码为A-Z的大写英文字母
第二码为1 or 2 的阿拉伯数字
第三码~第十码为1~99999999的任意数字,若小於10000000者补0,例:3000---->00003000
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
char firstWord;
int secondNumber, otherNumbers;
for (int i=0; i<100000; i++) {
firstWord= (char) ((int)(Math.random()*100)%26+65);
secondNumber= (int)((Math.random()*100)%2)+1;
otherNumbers= (int)(Math.random()*10000000);
System.out.println(firstWord+ secondNumber+ otherNumbers);
//System.out.printf("%c%d%08d\n", firstWord, secondNumber, otherNumbers);
}
}
}
上面有两行输出的程式码
我的问题在:我用未打注记的那行输出无法输出正确的身分证字号
用下面那行有注记的程式行则可以输出正确的身分证字号
上面那行出现的问题是:1.没有英文字母 2.数字长度不一
请问是为什麽呢?
又要如何修改才能像下面那行一样??
--
咪噜、扑扑
可爱~有时也很坏~
http://www.wretch.cc/album/album.php?id=b020306123&book=10
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.232.53.48
※ 编辑: liu2007 来自: 118.232.53.48 (08/16 20:26)
1F:推 now99:把 int 转型 成 string 08/16 20:44
2F:→ liu2007:可是前面要补0的地方怎麽办?补的长度也不一定一样@.@... 08/16 21:10
3F:→ szss8765:检查式? 08/16 22:58
4F:推 superlubu:java.text.DecimalFormat 08/17 06:41