package com.ityx.d3_static_test; import java.util.Random; /** * 工具类:验证码的功能实现 */ public class VerifyTool { //private VerifyTool(){} public static void main(String[] args) { System.out.println("验证码:" + createCode(5)); } public static String createCode(int n){ String chars = "abcdefghijklmnoqprstuvwxyzABCDEFGHIJKLMNOQPRSTUVWXYZ0123456789"; String code = ""; Random r = new Random(); for(int i = 0;i<n;i++){ int index = r.nextInt(chars.length()); code += chars.charAt(index); } return code; } }