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)));   
        }   
  • 相关阅读:
    10.28
    10.29
    11.05周四
    数据库增删改查
    11.03Tuesday
    11.10
    连接数据库
    10.30
    11.04周三
    10.27
  • 原文地址:https://www.cnblogs.com/jdonson/p/1617562.html
Copyright © 2011-2022 走看看