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("输入错误,对不起,您已经没有了输入机会");}
                }
        }
     }

    }

    
    

  • 相关阅读:
    pair和map
    lower_bound( )和upper_bound( )
    P1886 滑动窗口 /【模板】单调队列
    数的度(数位dp)
    最小生成树
    刷题-力扣-1052. 爱生气的书店老板
    刷题-力扣-766. 托普利茨矩阵
    刷题-力扣-28. 实现 strStr()
    刷题-力扣-697. 数组的度
    刷题-力扣-1004. 最大连续1的个数 III
  • 原文地址:https://www.cnblogs.com/HRZJ/p/5872139.html
Copyright © 2011-2022 走看看