码迷,mamicode.com
首页 > 移动开发 > 详细

随机生成手机号码

时间:2014-09-10 17:18:40      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   for   div   sp   log   on   

    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;
    }

 

随机生成手机号码

标签:style   blog   color   ar   for   div   sp   log   on   

原文地址:http://www.cnblogs.com/zhaojinhui/p/3964591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!