public class Text03 { public static void main(String[] args) { // 生成验证码 System.out.printf(creatCode(5)); } public static String creatCode(int n){ Random random=new Random(); String code=""; for (int i = 1; i <=n; i++) { int type=random.nextInt(3); switch (type){ case 0: // 表示要生成数字验证码 code +=random.nextInt(10); break; case 1: //表示生成大写字母验证码 char ch1=(char)(random.nextInt(26)+65); code+=ch1; break; case 2: //表示生成小写写字母的验证码 char ch2=(char)(random.nextInt(26)+97); code+=ch2; break; } } return code; } }
JAVA基础练习——验证码
最新推荐文章于 2024-07-24 17:27:32 发布