码迷,mamicode.com
首页 > 其他好文 > 详细

验证码

时间:2018-10-05 18:44:30      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:scan   void   ann   验证   oid   分享图片   lse   ati   can   

import java.util.Random;

import java.util.Scanner;

public class RandomStr {

public static void main (String []args){

 

 

       int length=6;

       System.out.println("请选择六位验证码中数字的位数:");

       Scanner scanner=new Scanner(System.in);

       int a=scanner.nextInt();

       if(a>6)

       {

              for(;a>6;)

              {

                     System.out.println("输入错误,请再次输入六以内的正整数:");

                     Scanner scannerc=new Scanner(System.in);

                     int c=scannerc.nextInt();

                     a=c;

              }

       }

      

       int b=length-a;

       if(b>0){

       System.out.println("则字母的位数为:"+b);

       System.out.println("请选择字母的大小写(大写选1     小写选2)");

       Scanner scannerz=new Scanner(System.in);

       int d=scannerz.nextInt();

       if(d>2||d<0)

       {

              for(;d>2||d<0;)

              {

                     System.out.println("输入错误,请按要求再次选择选择:");

                     System.out.println("大写选1     小写选2");

                     Scanner scannerc=new Scanner(System.in);

                     int c=scannerc.nextInt();

                     d=c;

              }

       }

      

       if(d==1){

              int x[]=new int[a];

              int Y[]=new int[b];

              char Y1[]=new char[b];

              System.out.print("生成的验证码为:");

              //验证码

             

              //数字的输入与输出

              for(int i=0;i<a;i++){

              x[i]=(int)(1+Math.random()*(9-1+1));

              }

              for(int i=0;i<a;i++){

              System.out.print(""+x[i]);

              }     

             

              //大写字母的输入与输出

              for(int j=0;j<b;j++){

              Y[j]=(int)(65+Math.random()*(90-65+1));

              Y1[j]=(char)Y[j];

              System.out.print(""+Y1[j]);

              }

       }

       else if(d==2){

              int x[]=new int[a];

              int Y[]=new int[b];

              char Y1[]=new char[b];

              System.out.print("生成的验证码为:");

              //验证码

             

              //数字的输入与输出

              for(int i=0;i<a;i++){

              x[i]=(int)(1+Math.random()*(9-1+1));

              }

              for(int i=0;i<a;i++){

              System.out.print(""+x[i]);

              }     

             

              //小写字母的输入与输出

              for(int j=0;j<b;j++){

              Y[j]=(int)(97+Math.random()*(122-97+1));

              Y1[j]=(char)Y[j];

              System.out.print(""+Y1[j]);

              }

       }

       }

       else if (b<=0){

       System.out.print("生成的验证码为:");

       int x=(int)(1+Math.random()*(999999-1+1));

       System.out.println(""+x);

       }

      

      

}

}

 技术分享图片

 

技术分享图片

 

 

 技术分享图片

 

验证码

标签:scan   void   ann   验证   oid   分享图片   lse   ati   can   

原文地址:https://www.cnblogs.com/muailiulan/p/9745239.html

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