Requirements: twenty randomly generated phone numbers
1 package com.random; 2 3 import java.util.Scanner; 4 5 public class Phone { 6 static Scanner sc = new Scanner(System.in); 7 public static void getPhoneNum() { 8 //设置手机号初始前三位 9 String[] Top3 = {"133", "149", "153", "173", "177", 10 "180", "181", "189", "199", "130", "131", "132", 11 "145", "155", "156", "166", "171", "175", "176", "185", "186", "166", "134", "135", 12 , "136", "137", "138", "139", "147", "150", "151", "152", "157", "158", "159", "172" , 13 "178", "182", "183", "184", "187", "188", "198", "170", "171" }; 14 15 // random real number section illustrating the use of an array length properties, to obtain the array length, 16 // () * the array length by array subscript Math.random obtained, whereby a random number section in the top three . 17 String firstNum Top3 = [( int ) (Math.random () * Top3.length )]; 18 // random the remaining 8 bits . 19 String = lastNum ""; 20 final int last = 8; 21 for (int0 = I; I <Last; I ++ ) { 22 is // each cycle selected from 0 to 9, a random number 23 is lastNum + = ( int ) (Math.random () * 10 ); 24 } 25 // finally number mantissa segment connecting and 26 is String phoneNum + = firstNum lastNum; 27 System.out.println (phoneNum); 28 } 29 30 31 is public static void main (String [] args) { 32 // generate twenty phone number 33 is int 20 is = NUM ; 34 is System.out.println ( "phone number as follows:" ); 35 for (int i = 0; i < num; i++) { 36 getPhoneNum(); 37 } 38 } 39 }