首页 > 代码库 > Java 中常用代码 (欢迎补充)

Java 中常用代码 (欢迎补充)

//------------------------------------------------------------------------------------------------------

生成四位随即验证码

String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  StringBuilder s = new StringBuilder();
  int len = 4;
  for(int i=0;i<=len;i++){
   Random r = new Random();
   int p = r.nextInt(str.length());
   s.append(str.charAt(p));
  }
  System.out.println(s.toString());

//------------------------------------------------------------------------------------------------------

 

Java 中常用代码 (欢迎补充)