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

    }

    
    

  • 相关阅读:
    串口数据字节位的理解
    【转】arm-none-linux-gnueabi-gcc下载
    【转】网络排错全面详解
    【转】VMware虚拟机三种网络模式详解
    【转】vi编辑只读文档无法保存的解决办法
    【转】关于在linux下清屏的几种技巧
    【转】64位Ubuntu 16.04搭建嵌入式交叉编译环境arm-linux-gcc过程图解
    ELF文件
    UCOSII内核代码分析
    vmware安装win7提示No CD-ROM drive to use:GCDROM not loaded
  • 原文地址:https://www.cnblogs.com/HRZJ/p/5872139.html
Copyright © 2011-2022 走看看