0226作业

第一题

 

 1 package com.kgc.zuoye.zy0226;
 2 
 3 import java.util.Random;
 4 
 5 //随机9个电话号码,随机数第2个数开始(不包含0-2)
 6 public class Zuoye01 {
 7     public static void main(String[] args){
 8         Random rd=new Random();
 9         int num2=0,num3=0;
10         System.out.println("随机生成9个电话号码:");
11         for (int i=1;i<=9;i++){
12             num2=rd.nextInt(10);
13             while (num2>=0&&num2<3){
14                 num2=rd.nextInt(10);
15             }
16             num3=rd.nextInt(999999999);
17             while (num3<100000000){
18                 num3=rd.nextInt(999999999);
19             }
20             System.out.println("1"+num2+num3);
21         }
22     }
23 }

运行结果

 

 

 

 

 

第二题,通过数组产生6位数随机验证码

 

 1 package com.kgc.zuoye.zy0226;
 2 
 3 import java.util.Random;
 4 
 5 //随机生成6位的验证码,要求有数字大写\小写\字母组成
 6 public class Zuoye02 {
 7     public static void main(String[] args){
 8         char[] c={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k','l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
 9         10         Random rd=new Random();
11         System.out.print("六位数验证码是:");
12         for (int i=0;i<6;i++){
13            System.out.print(c[rd.nextInt(c.length)]);
14         }
15     }
16 }

 

运行结果

 

posted @ 2019-02-26 11:36  纯属丶简单  阅读(136)  评论(0编辑  收藏  举报