随机生成一个6位数验证码,包含大小写字母及数字

package com.bdqn;

import java.util.Random;

public class Code {
    public static void main(String[] args) {
        Random random = new Random();
        int[] nums = new int[6];
        for(int i = 0 ; i < 6 ; i++){
            do{
                nums[i] = random.nextInt(123);
                if(nums[i] >= 0 && nums[i] <= 9){
                    System.out.print(nums[i]);
                    break;
                }else if(nums[i] >= 65 && nums[i] <= 90){
                    char num = (char) nums[i];
                    System.out.print(num);
                    break;
                }else if(nums[i] >= 97 && nums[i] <= 122){
                    char num = (char) nums[i];
                    System.out.print(num);
                    break;
                }
            }while(true);
        }
    }
}

运行结果

 

posted @ 2019-02-26 11:26  杨文祥  阅读(2346)  评论(0编辑  收藏  举报