英文:
How to create barcode in Java
问题
public String barcode()
{
String bar = "";
String alphs = "ABCDFEJKZCVBNMFTYWQRTNMGFDS";
char al[] = alphs.toCharArray();
int n1 = (int) ((Math.random() * 100) % 26);
int n2 = (int) ((Math.random() * 100) % 26);
int n3 = (int) ((Math.random() * 100) % 26);
int n4 = (int) ((Math.random() * 100) % 10);
int n5 = (int) ((Math.random() * 100) % 10);
int n6 = (int) ((Math.random() * 100) % 10);
bar = al[n1] + "" + al[n2] + "" + al[n3] + "-" + n4 + "" + n5 + "" + n6;
return bar;
}
(Note: The provided code seems to generate a random barcode using a combination of letters and numbers.)
英文:
I want to create a barcode in Java. I tried the following code, but barcode created and displayed an error on console:
> Exception in thread "AWT-EventQueue-0"
> java.lang.NumberFormatException: empty String
What I tried so far I attached below
public String barcode()
{
String bar = "";
String alphs ="ABCDFEJKZCVBNMFTYWQRTNMGFDS";
char al[] = alphs.toCharArray();
int n1 =(int)((Math.random()*100)%26);
int n2 =(int)((Math.random()*100)%26);
int n3 =(int)((Math.random()*100)%26);
int n4 =(int)((Math.random()*100)%10);
int n5 =(int)((Math.random()*100)%10);
int n6 =(int)((Math.random()*100)%10);
bar = al[n1]+ ""+ al[n2]+""+ al[n3]+"-"+ n4+ ""+ n5+ ""+ n6;
return bar;
}
答案1
得分: 0
这段代码在6000000次循环中是正确的。
for (int i = 0; i < 6000000; i++) {
String barcode = barcode();
System.out.println(barcode);
}
请检查您的环境。
英文:
This code is correct by 6000000 counts.
for (int i = 0; i <6000000 ; i++) {
String barcode = barcode();
System.out.println(barcode);
}
Please check your environment.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论