• 验证码输出


     

     

    实验四

    1设计思想:随机在一定范围内六位随机数,在65到90或者97到122之间的数自动转化为字母输出,组成六位验证码,再让用户输入验证码判定正确与否

    2流程图:

    3源程序代码:

    //1603 李敦岳 20163520

    //验证码的输出

    //2017.10.2

    import javax.swing.JOptionPane;

    public class RandomString

    {

    public static void main(String[] args)

    {

    //定义一个空字符串

    String result = "";

    String Str;

    //进行6次循环

    for(int i = 0 ; i < 6 ; i ++)

    {

    //生成一个97122int型的整数

    int intVal = (int)(Math.random() * 122+ 0);

    if((intVal<=90&&intVal>=65)||(intVal>=97&&intVal<=122))

    {//intValue强制转换为char后连接到result后面

    result = result + (char)intVal;

    }

    else

    {

    int intVal2= (int)(Math.random() * 10+ 0);

    result=String.valueOf(intVal2)+result;

    }

    }

    //输出随机字符串

           //输入字符串,弹出提示框

    Str=

        JOptionPane.showInputDialog( "输入验证码"+result );

    if(Str.equals(result))//正确输入

    { JOptionPane.showMessageDialog(

          null, "输入正确,请稍后","Results",

          JOptionPane.PLAIN_MESSAGE );}

    else//错误输入

    {

    JOptionPane.showMessageDialog(

          null, "输入错误,请重来","Results",

          JOptionPane.ERROR_MESSAGE );

    }

    System.exit( 0 );

    //System.out.println(result);

      }

    }

    4.程序截图:

     

  • 相关阅读:
    JDK介绍
    选择器——过滤选择器——内容过滤器
    选择器——过滤选择器——基本过滤器
    选择器——层次选择器
    选择器——基本选择器
    jQuery 对象转成 DOM 对象
    dom转换成jquery对象
    Android-bindService本地服务-初步-Service返回对象
    Android-bindService本地服务-初步
    Android-Service生命周期
  • 原文地址:https://www.cnblogs.com/ldy1998/p/7632824.html
Copyright © 2020-2023  润新知