随机产生4位数的验证码

package com.softeem.math;

import java.util.Random;

public class YanZhengMa {

		public static String checkcode(){
			String temp = "";
			Random rd = new Random();
			for (int i = 0; i < 4; i++) {
				int m = rd.nextInt(3);
				 switch (m) {
		            case 0: 
		                char c1 = (char) (rd.nextInt(26) + 65);
		                temp += c1;
		                break;
		            case 1: 
		                char c2 = (char) (rd.nextInt(26) + 97);
		                temp += c2;
		                break;
		            case 2: 
		                int num = rd.nextInt(10);
		                temp += num;
		                break;
		            }
		        }
			     return temp;
			}


         public static void main(String[] args) {

         String checkcode = YanZhengMa.checkcode();
         System.out.println(checkcode);
    }
}
	

猜你喜欢

转载自blog.csdn.net/qq_42696837/article/details/81158032