抽奖

参考来源:http://www.cnblogs.com/hellodp/p/5134815.html

 

 1 package com.zuoye;
 2 
 3 import java.util.*;
 4 
 5 public class yanzhengma {
 6 
 7 public static void main(String[] args) {
 8         
 9 
10 String ran1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789";
11 
12 int number = ran1.length();
13 
14 Random ran = new Random();
15 
16 System.out.print("生成验证码:");
17 
18 for(int i=0; i<4; i++)
19 {
20 int a = ran.nextInt(number-1);
21 
22 String a1 = ran1.substring(a, a+1);
23 
24 System.out.print(a1);
25 
26 }
27 }
28 }

刷新一次出现一次新的验证码

 

 1 package com.zuoye;
 2 
 3 import java.util.Random;
 4 
 5 public class choujiang{
 6 
 7 public static void main(String[]args){
 8 
 9         int[]cp=new int[7];
10 
11     Random dom=new Random();
12 
13     System.out.println("抽到的彩票号码是:");
14 
15     for(int i=0;i<cp.length;i++)
16     {
17         int t=dom.nextInt(36);
18         if(t==0)
19         {
20             i--;
21             continue;
22         }
23 
24         else
25         {
26             boolean h=false;
27             for(int c:cp)
28             {
29                 if(c==t)
30                 {
31                     i--;
32                     h=true;
33                     break;
34                 }
35             }
36             if(h)
37             {
38                 continue;
39             }
40         }
41         cp[i]=t;    
42         }
43 
44     for(int c:cp)
45     {
46         System.out.print(c+"");
47     }
48         System.out.println("\n");
49     }
50 }

 

posted @ 2016-03-11 21:17  宫崎天川  阅读(114)  评论(0编辑  收藏  举报