package com.bao;
import java.util.Random;
import java.util.Scanner;public class Yanzhengma1 {
public static void main(String[] args) { String a="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; Random ran=new Random(); int[] b=new int[4]; for(int j=4;j>-1;j--) //五次机会 { for (int i=0;i<4;i++) //四个随机数 { b[i]=ran.nextInt(63); } String d=new String(); for(int i=0;i<4;i++) { System.out.print(a.charAt(b[i])+" "); d=d+a.charAt(b[i]); }System.out.println(""); Scanner sc=new Scanner(System.in); System.out.print("请输入上面验证码:"); String c=sc.nextLine(); if(c.equals(d)) { System.out.println("输入正确!"); break; } else if(j>0) { System.out.println("输入错误,您还有"+j+"次机会"); } else { System.out.println("对不起,你没有机会了!"); } } }
}