zoukankan      html  css  js  c++  java
  • 用Random类输出验证码

     1 package dx;
     2 
     3 import java.text.DecimalFormat;
     4 import java.util.Random;
     5 
     6 public class DxL { //创建类
     7     
     8     public static void main(String[] args)
     9     {        
    10         String str = "1234567890abcdefghijklmnopqistuvwxyz";//定义包含所有数字字母的字符串
    11         
    12         Random sj = new Random();//实例化一个Random类
    13         
    14         System.out.print("生成4位验证码 = ");
    15         
    16         for(i = 0; i < 4 ; i++)
    17         {
    18             int sy = sj.nextInt(36);//产生一个大于等于0小于36的整数随机数
    19             System.out.print(str.substring(sy , sy+1));//输出截取的字符串str中索引为sy的子串
    20         }
    21             
    22     }
    23 
    24 }
  • 相关阅读:
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日博客
    每日博客
    结对作业之全国疫情统计可视化地图
    每日博客
  • 原文地址:https://www.cnblogs.com/dirgo/p/4871318.html
Copyright © 2011-2022 走看看