zoukankan      html  css  js  c++  java
  • 随机生成4位验证码,输入验证码与生成的比较,最多输入5次

    
    

    package com.hanqi.lianxi;

    import java.util.Random;
    import java.util.Scanner;

    public class yanzhengma
    {

     public static void main(String[] args)
     {
             String str ="0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";
             char[] array = new char[4];
             Random suiji = new Random();
             System.out.print("验证码为:");
             for(int i =0; i<4; i++)
             {          
              array[i]=str.charAt(suiji.nextInt(61));         
             }
             System.out.println(array);
             Scanner sr = new Scanner(System.in);
             System.out.println("请输入验证码:");     
        String aaa=new String(array);//把数组类型转换成字符串类型
        for(int j=0;j<5;j++)
        {
                if(sr.nextLine().equals(aaa))
                {
                 System.out.println("输入正确");
                 break;
                }
                else
                {
                 if(j<=3)
                     {
                  System.out.println("输入错误,请重新输入");
                  System.out.print("验证码为:");
                        for(int i =0; i<4; i++)
                        {          
                         array[i]=str.charAt(suiji.nextInt(61));         
                        }
                        System.out.println(array);
                         aaa=new String(array);
                  }
                 else
                 {System.out.println("输入错误,对不起,您已经没有了输入机会");}
                }
        }
     }

    }

    
    

  • 相关阅读:
    mysql 取年、月、日、时间
    第4步:创建RAC共享磁盘组
    第3步:添加用户与安装路径
    第2步:配置系统安装环境
    第1步:安装虚拟机+配置网络
    nodejs rar/zip加密压缩、解压缩
    使用shell脚本守护node进程
    抒发一下这些天用django做web项目的一些体会
    编写gulpfile.js文件:压缩合并css、js
    在NodeJS中使用流程控制工具Async
  • 原文地址:https://www.cnblogs.com/HRZJ/p/5872139.html
Copyright © 2011-2022 走看看