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