20 randomly generated phone number, to be perfect

 

 1 package com.homework;
 2 
 3 import java.util.HashSet;
 4 import java.util.Set;
 5 
 6 public class RandomPhone {
 7     //初始化手机前三位
 8     static String[] First = {"139","138","137","136","135","134","159","158","157", 
 9             "150","151","152","188","130","131","132","156","135","133","153","189"};
//12 is();
HashSet <String>new newthe Set <String> = PhoneSetstatic. 11phone unique random number//10     
          static Set<String> phoneSet = new HashSet<String>();
13     
14     //getNumber方法来获得数字
15     public static int getNumber(int start,int end) {
16         int sum = (int)(Math.random()*(end+1-start)+start);
17         return sum;
18     }
19     public static void main(String[] args) {
20         String first = null;
21         String second = null;
22         String third = null ;
 23 is          
24          
25          
26 is          for (; phoneSet.size () <20 is ;) {
 27              // phone number of the top three 
28              int index = the getNumber (0,-First.length. 1 );
 29              First = First [index];
 30              // the substring from the beginning of the string action is specified position
 31              // generated phone number 8 remaining 
32              SECOND = String.valueOf (the getNumber (0,99999) +100000 );
 33 is              THIRD String.valueOf = (the getNumber ( 0,999) of +1000 );
 34 is  //             SECOND = String.valueOf (the getNumber (0,99999) +100000) .substring (0);
 35 //            third = String.valueOf(getNumber(0,999)+1000).substring(0);
36             String ch = first+second+third;
37             phoneSet.add(ch);
38         }
39         int i = 0;
40         for(String sc :phoneSet) {
41             System.out.println("第"+(++i)+"的手机号是"+sc);
42         }
43     }
44 }

 

Guess you like

Origin www.cnblogs.com/lev1/p/11275501.html