JAVA小练习97——需求: 实现一个4位的验证码

import java.util.Random;


public class Demo97 {
	
	
	public static void main(String[] args) {
		char [] arr= {'a','A','中','雨','共','W','O','1','9','4','t','方','G','忍','y','q','O','6','2','0'};
		
		Random random =new Random();
		StringBuilder s = new StringBuilder();
		
		for(int i=0;i<4;i++) {
			int index = random.nextInt(arr.length);
			char temp = arr[index];
			s.append(temp);
		}
		System.out.println("验证码:"+s);
		
	}
	
}

你可能感兴趣的:(java)