乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      隨機生成5位大小寫字母或者數(shù)字

       yan的圖書41 2017-07-17

      隨機生成5位大小寫字母或者數(shù)字

      方法一:生成不重復(fù)的

      1. public static void main(String[] args) {  
      2.         Random rand = new Random();  
      3.         char[] letters=new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q',  
      4.                 'R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i',  
      5.                 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','r',  
      6.                 '0','1','2','3','4','5','6','7','8','9'};  
      7.         String str = "";  
      8.         int index;  
      9.         boolean[] flags = new boolean[letters.length];//默認為false  
      10.         for(int i=0;i<5;i++){  
      11.             do{  
      12.                 index = rand.nextInt(letters.length);   
      13.             }while(flags[index]==true);  
      14.             char c = letters[index];  
      15.             str += c;  
      16.             flags[index]=true;  
      17.         }  
      18.         System.out.println(str);  
      19.     }  

      方法二:生成重復(fù)的,與方法一類似

      1. public static void main(String[] args) {  
      2.         Random rand = new Random();  
      3.         char[] letters=new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q',  
      4.                 'R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i',  
      5.                 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','r',  
      6.                 '0','1','2','3','4','5','6','7','8','9'};  
      7.         String str = "";  
      8.         int index;  
      9.         boolean[] flags = new boolean[letters.length];//默認為false  
      10.         for(int i=0;i<5;i++){  
      11.             do{  
      12.                 index = rand.nextInt(letters.length);   
      13.             }while(flags[index]==true);  
      14.             char c = letters[index];  
      15.             str += c;  
      16.             flags[index]=true;  
      17.         }  
      18.         System.out.println(str);  
      19.     }  
      方法三:生成重復(fù)的(建議選用此方法)
      1. public static void main(String[] args) {  
      2.         String str = "";  
      3.         Random rand = new Random();  
      4.         for(int i=0;i<5;i++){  
      5.             int num = rand.nextInt(3);  
      6.             switch(num){  
      7.                 case 0:  
      8.                     char c1 = (char)(rand.nextInt(26)+'a');//生成隨機小寫字母   
      9.                     str += c1;  
      10.                     break;  
      11.                 case 1:  
      12.                     char c2 = (char)(rand.nextInt(26)+'A');//生成隨機大寫字母   
      13.                     str += c2;  
      14.                     break;  
      15.                 case 2:  
      16.                     str += rand.nextInt(10);//生成隨機數(shù)字  
      17.             }  
      18.         }  
      19.         System.out.println("生成的5個隨機驗證碼是:"+str);  
      20.     }  




        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多