try:int genInt(int n){
int result = 0;
byte[] byts = new byte[n];
for(int i = 0; i < n; i++){
byts[i] = (byte)(Math.random() * 10);
if(i == 0){
while(byts[0] == 0)
byts[0] = (byte)(Math.random() * 10);
}
for(int j = 0; j < i; j++)
if(byts[i] == byts[j]){
byts[i] = (byte)(Math.random() * 10);
j = -1;
continue;
}
result = result * 10 + byts[i];
}
return result;
}
int result = 0;
byte[] byts = new byte[n];
for(int i = 0; i < n; i++){
byts[i] = (byte)(Math.random() * 10);
if(i == 0){
while(byts[0] == 0)
byts[0] = (byte)(Math.random() * 10);
}
for(int j = 0; j < i; j++)
if(byts[i] == byts[j]){
byts[i] = (byte)(Math.random() * 10);
j = -1;
continue;
}
result = result * 10 + byts[i];
}
return result;
}
解决方案 »
- for循环题目:求代码打印出下图。
- 为什么在新建对象后面跟了一个方法。。。
- 麻烦帮我修改一个正则表达式吧~
- 求教—java中多个类和对象的应用问题
- 调用Frame的dispose方法后再new Frame的问题
- 谁有jdk1.3 for linux,sun不提供下载了,搜索好久没找到。100分
- 大家谈谈JDK的配置
- 有谁知道关于Java Web Start?
- 用JAVA如何与打印机连接,并打印文件!
- JB中的Error:(59)incompatible types;found:java.lang.String,required:int.
- 如何做到窗口最大化????
- 如何把Applet的运行机制运用到Application中?
int ran = Math.abs(rand.nextInt(9000)+1000);
String str = Integer.toString(ran);
while(str.charAt(0)==str.charAt(1)||str.charAt(0)==str.charAt(2)
||str.charAt(0)==str.charAt(3)||str.charAt(1)==str.charAt(2)
||str.charAt(1)==str.charAt(3) ||str.charAt(2)==str.charAt(3) )
ran = Math.abs(rand.nextInt(9000)+1000);为什么不行呢?
||str.charAt(0)==str.charAt(3)||str.charAt(1)==str.charAt(2)
||str.charAt(1)==str.charAt(3) ||str.charAt(2)==str.charAt(3) ){
ran = Math.abs(rand.nextInt(9000)+1000);
str = Integer.toString(ran);//U have to reassign variable str
}