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

    }

    
    

  • 相关阅读:
    数据分析入门_char01
    [转]在Goolge安装谷歌插件Postman
    Ubutu 14.04 Fiddler Android抓包
    Ubuntu14.04 install appium
    【转】ubuntu修改时区和时间的方法
    MongoDB权威指南<2> 1-2 MongoDB 介绍
    python数据类型-字典
    python数据类型-列表
    python数据类型-字符串
    python编码以及格式化输出
  • 原文地址:https://www.cnblogs.com/HRZJ/p/5872139.html
Copyright © 2011-2022 走看看