`
wjm901215
  • 浏览: 147752 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

随机生成随机数+字母

    博客分类:
  • java
 
阅读更多

for(int i = 0; i < 15; i++) 
        { 
            String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字 
            if("char".equalsIgnoreCase(charOrNum)) // 字符串 
            { 
                 int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; //取得大写字母还是小写字母 
                 val += (char) (choice + random.nextInt(26)); 
            } 
             else if("num".equalsIgnoreCase(charOrNum)) // 数字 
            { 
                     val += String.valueOf(random.nextInt(10)); 
            } 
        }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics