package com.lei.common;
public class VerificationCode {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String sum = "";
for (int i = 0; i < 4; i++) {
//也可以随机生成不同类型组成的四位随机数
//int p = getPos(); switch (p)
switch (i) {
case 0:
sum += getUpperCase();
break;
case 1:
sum += gerLowerCase();
break;
case 2:
sum += getNumCase();
break;
case 3:
sum += getUpperCase();
break;
}System.out.println(sum);
}
System.out.println(sum);
}
// A-Z
public static char getUpperCase() {
return (char) (((int) Math.random() * 26)+65);
}
public static char gerLowerCase() {
return (char) (((int) Math.random() * 26)+ 97);
}
public static int getNumCase() {
return (int)( Math.random() * 10);
}
public static int getPos() {
return (int)( Math.random()*3);
}
}
java 生成四位验证码
最新推荐文章于 2024-05-07 16:08:33 发布