验证码

import java.util.Random;

import java.util.Scanner;

public class Test{

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);

       }

}

}

 

posted @ 2018-10-07 23:05  故事-已开始。  阅读(87)  评论(0编辑  收藏  举报