zoukankan      html  css  js  c++  java
  • java生成随机字母

     

    代码
    方法一:
    public class RandomTest extends TestCase {   
        
    public void testRandom1() throws Exception {   
            String s 
    = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";   
            
    char[] c = s.toCharArray();   
            Random random 
    = new Random();   
            
    forint i = 0; i < 8; i ++) {   
                System.out.println(c[random.nextInt(c.length)]);   
            }   
        }   
    }  


    方法二:
    public void testRandom2() throws Exception {   
        Random random 
    = new Random();   
        
    forint i = 0; i < 8; i ++) {   
            
    int choice = random.nextInt(2% 2 == 0 ? 65 : 97// 取得大写还是小写   
            System.out.println((char)(choice + random.nextInt(26)));   
        }   
  • 相关阅读:
    Swift 构造与析构
    Swift 协议
    Swift 扩展
    Swift 多态
    Swift 继承
    Swift 封装
    Swift 方法
    Swift 属性
    Swift 对象
    Swift 类
  • 原文地址:https://www.cnblogs.com/jdonson/p/1617562.html
Copyright © 2011-2022 走看看