您的位置:首页 > 其它

随机生成四位不同数字

2017-07-30 11:47 295 查看
随机生成4位不同数字

import java.util.Random;
/**
*
* Class Name: FourRandomUtils.java
* Function:
* 自动生成四位不相同的数字
* Modifications:
*
* @author zhou DateTime 2017年7月27日 上午11:18:32
* @version 1.0
*/
public class FourRandomUtils {
public static String getFourNum() {
Random r=new Random();
int tag[]={0,0,0,0,0,0,0,0,0,0};
String four="";
int temp=0;
while(four.length()!=4){
temp=r.nextInt(10);//随机获取0~9的数字
if(tag[temp]==0){
four+=temp;
tag[temp]=1;
}
}
return four;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: