1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| import java.util.Scanner;
public class RandomPhoneNum { static Scanner sc = new Scanner(System.in);
public int getooo(){ return 1;} public static void main(String[] args) {
boolean boo = true;
int num = 0;
do {
System.out.println("你需要多少组电话号码,请输入一个整数");
String answer = sc.next();
try {
num = Integer.parseInt(answer);
boo = false;
} catch (Exception e) {
System.out.println("你输入的不是一个整数,请重新输入");
}
} while (boo);
System.out.println("你要的手机号码如下:");
for (int i = 0; i < num; i++) {
getPhoneNum();
}
}
public static void getPhoneNum() {
String[] start = {"133", "149", "153", "173", "177",
"180", "181", "189", "199", "130", "131", "132",
"145", "155", "156", "166", "171", "175", "176", "185", "186", "166", "134", "135",
"136", "137", "138", "139", "147", "150", "151", "152", "157", "158", "159", "172",
"178", "182", "183", "184", "187", "188", "198", "170", "171"};
String phoneFirstNum = start[(int) (Math.random() * start.length)];
String phoneLastNum = "";
final int LENPHONE = 8;
for (int i = 0; i < LENPHONE; i++) {
phoneLastNum += (int) (Math.random() * 10);
}
String phoneNum = phoneFirstNum + phoneLastNum;
System.out.println(phoneNum);
}
}
|