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();
}
}
解决 无用评论 打赏 举报