• 验证码


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

           }

    }

    }

  • 相关阅读:
    在线教育项目-day07【添加分类前端】
    在线教育项目-day07【课程分类显示接口】
    在线教育项目-day05【实现EasyExcel对Excel操作】
    在线教育项目-day05【上传头像实现】
    在线教育项目-day05【nginx】
    在线教育项目-day05【Swagger问题】
    在线教育项目-day05【上传头像功能】
    在线教育项目-day04【路由问题】
    在线教育项目-day04【后台讲师修改功能】
    在线教育项目-day04【后台讲师添加模块】
  • 原文地址:https://www.cnblogs.com/yishaui/p/9751969.html
Copyright © 2020-2023  润新知