实验一任务四:验证码问题

package shiyansi;

import javax.swing.JOptionPane;
public class RandomStr {

public static void main(String[] args) {
// TODO 自动生成的方法存根
//定义一个空字符串

String result = "",first;
int number1,number2;
//进行6次循环
for(int i = 0 ; i < 6 ; i ++)
{
//生成一个97~122的int型的整数
int intVal = (int)(Math.random() * 26 + 97);

//将intValue强制转换为char后连接到result后面
result = result + (char)intVal;
}

first =
JOptionPane.showInputDialog( "The code is:"+result);


if(first.equals(result))//判断是否输入正确正确输出Success错误输出Error
{
JOptionPane.showMessageDialog(
null, "Success! "

);
System.exit( 0 ); //退出程序
}
else
{
JOptionPane.showMessageDialog(
null, "Error!"

);
System.exit( 0 ); //退出程序
}

}

}

原文地址:https://www.cnblogs.com/mqlblog/p/7613251.html