package YAN;
import javax.swing.*;
import java.util.Random;
public class yanzheng {
static Random random = new Random();
public static void main(String[] args)
{
String s = "";
for(int i=1;i<=4;i++ )//获取未知验证码,存储与字符串中
{
boolean p = random.nextBoolean();
int q;
if(p)
{
q = random.nextInt(26)+65;
}
else
{
q = random.nextInt(26)+97;
}
s = s + (char)q;
}
//显示对话框,并输入信息
int t;
do {
String s1 = JOptionPane.showInputDialog(s+"\n"+"请输入验证码(区分大小写):");
if(s1.equals(s))
{
//若输入正确
JOptionPane.showMessageDialog(null,"输入正确!","结果:",JOptionPane.PLAIN_MESSAGE);
t=0;
}
else
{
//若输入错误
JOptionPane.showMessageDialog(null,"输入错误!","结果:",JOptionPane.PLAIN_MESSAGE);
t=1;
}
}while(t==1);
System.exit( 0 );
}
}