package com.Demo; import java.util.Random; //随机验证码 public class Test2 { public static void main(String[] args) { System.out.println(cali(5)); } public static String cali(int n){ Random r=new Random(); String code=""; for (int i = 1; i <=n ; i++) { int type=r.nextInt(3); switch (type){ case 0: code+=r.nextInt(10); break; case 1: char ch1= (char) (r.nextInt(26)+65); code+=ch1; break; case 2: char ch2= (char) (r.nextInt(26)+97); code+=ch2; break; } } return code; } }
标签:String,int,Random,验证码,随机,public From: https://www.cnblogs.com/Karl-hut/p/17437969.html