总结:还是掌握方法的运用++++++
package com.c2;
//随机数组合,随机号码产生器
//随机号码
import java.util.Random;
public class rfe {
private static Random random = new Random();
public static String getRandom(String[] a, int length, int alength) {
StringBuffer x = new StringBuffer();
for (int i = 0; i < length; i++) {
x.append(String.valueOf(a[random.nextInt(alength)]));
}
return x.toString();
}
public static void main(String[] args) {
String a[] = new String[] { "2", "4", "5", "3", "7", "8", "1", "6" };// 输入的是字符串,对于StringBuffer
System.out.println(getRandom(a, 10, 5));// 这里的10为数组元素个数,5为随机产生的数个数
}
}
//
522745