标签:sum 指定位置 数字 star system cond class color eof
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"}; 10 //手机号唯一 无序 11 static Set<String> phoneSet = new HashSet<String>(); 12 //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 24 25 26 for(;phoneSet.size() <20;) { 27 //手机号前三位 28 int index = getNumber(0,First.length-1); 29 first = First[index]; 30 // substring 的作用是从指定位置开始字符串 31 //生成手机剩下的8位号码 32 second = String.valueOf(getNumber(0,99999)+100000); 33 third = String.valueOf(getNumber(0,999)+1000); 34 // second = String.valueOf(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 }
标签:sum 指定位置 数字 star system cond class color eof
原文地址:https://www.cnblogs.com/lev1/p/11275501.html