随机生成手机号码

    public static void main ( String[] args )
    {
       
        Test t = new Test();
        for (int i = 0; i < 100; i++) //随机生成100个手机号码
        {
            System.out.println(t.getPhone());
        }
        
    }
    /**
     * 随机生成11位手机号码
     */
    public String getPhone(){
        
        String 移动[]={"134","135","136","137","138","139","150","151","152","157","158","159","187","188"};
        String 联通[]={"130","131","132","155","156","185","186","145"}; 
        String 电信[]={"133","153","180","181","189"}; 
        String tel[][]={移动,联通,电信};
        Random rd=new Random();
        int index = rd.nextInt(tel.length);//运营商个数
        int size = rd.nextInt(tel[index].length); //各运营商号码个数
        String phone=tel[index][size]+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10)+""+rd.nextInt(10);
        return phone;
    }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。