daliuliu_01 2017-07-07 07:49 采纳率: 100%
浏览 1549

Java算法0-9和A-Z组成的10位数的所有可能性

Java算法0-9和A-Z组成的10位数的所有可能性,可以重复

  • 写回答

3条回答

  • DN-CS BISHA 2017-07-07 08:12
    关注

    这一共有 36 的 10 次方 个可能值。 我只能随机的取其中的一个值 。

    package sun.rain.amazing.util;

    /**

    • Created by sunRainAmazing on SUN_RAIN_AMAZING *
    • @author sunRainAmazing
      */
      public class NumUtil {

      public static void main(String[] args){
      System.out.println(testRandom(10));
      }

      public static String testRandom(int length){
      String str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      char[] ch = str.toCharArray();
      StringBuffer sb = new StringBuffer("");
      for(int i=0; i<length; i++){
      sb.append(ch[(int)Math.round(Math.random()*(ch.length-1))]);
      }
      return sb.toString();
      }
      }

    评论

报告相同问题?