package cn.itcast1;
import java.util.Random;
public class Demo2 {
public static void main(String[] args) {
Random sj=new Random();
String str="1";
int[] arr={3,5,7,8};
it:while(true){
str=str+arr[sj.nextInt(arr.length)];
for(int i=0; i<9; i++){
int s=sj.nextInt(10);
str=str+s;
}
String regax="1[3578]\\d{9}";
boolean flag=str.matches(regax);
if(flag){
System.out.println("随机生成号码成功");
System.out.println("生成的号码是:"+str);
break it;
}else{
System.out.println("不合适的手机号码");
}
}
}
}
|
|