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 }

 

相关文章:

  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2022-02-13
  • 2021-11-18
  • 2021-12-19
  • 2021-07-23
猜你喜欢
  • 2022-12-23
  • 2021-12-07
  • 2021-11-06
  • 2021-11-20
  • 2022-12-23
  • 2021-06-11
  • 2021-07-13
相关资源
相似解决方案