验证码

1.设计思路

利用random和循环生成随机六位字符串作为验证码,然后根据提示输入,接着判断是否正确。

2.流程图

3.源代码

import javax.swing.JOptionPane;
public class Vcode
{
public static void main(String[] args)
{
String result = "";
for(int i = 0 ; i < 6 ; i ++)
{
int intVal = (int)(Math.random() * 26 + 97);
result = result + (char)intVal;
}
String code;
code=JOptionPane.showInputDialog(result+"\n请输入验证码");
if(code.equals(result))
{
JOptionPane.showMessageDialog(null,"验证通过","验证结果",JOptionPane.PLAIN_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null,"验证失败","验证结果",JOptionPane.PLAIN_MESSAGE);
}

}

}

 

4.截图

 

posted @ 2017-10-08 16:27  但为君故。  阅读(423)  评论(0编辑  收藏  举报