Java教程

随机手机号

本文主要是介绍随机手机号,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

方法一:

//定义手机号前3位
String[] FirstThreeNumber = {"134","135","136","137","138","139","147","150","152","157","158","159","172","178","182","183","184","187","188","198","130","131","132","145","155","156","166","171","175","176","185","186","166","133","149","153","173","177","180","181","189","199"};
 
//随机获取前三位手机号的index
int n= (int)(Math.random() * FirstThreeNumber.length);
//int n= (int)(Math.random()*(3-1)+1); //设置一个1到3的变量
//int n= (int)(Math.random()*5);  //设置一个0到4的变量

//获取手机前三位
String yy = FirstThreeNumber[n];
//循环获取手机号后8位
for(int i = 0; i < 8; i++){
	int x = (int)(Math.random() * 9); //设置一个0到8的变量
	yy = yy + x;
};
vars.put("com_phone", yy);

 

方法二:

//现在设置一个用户初始变量手机号,然后在这里获取
String aa=vars.get("beginPhone");

//log.info("获取手机号: "+aa);

Long phone2 =Long.valueOf(aa);

//每次加一
phone2 = phone2+1;

String newPhone=String.valueOf(phone2);

//log.info(newPhone);

vars.put("beginPhone",newPhone);

 

这篇关于随机手机号的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!