编写一个方法,返回1到54之间的随机数,但不能是传递到实参中的数。指定如下方法头:
public static int getRandom(int… numbers)
package pack2;
import java.security.SecureRandom;
public class Randomer {
public static void main(String[] args) {
int i = 0;
while(i++ < 10)
System.out.print(" "+getRandom(12, 53, 42, 45, 23));
}
/**随机数选择器*/
public static int getRandom(int...numbers) {
int random = 1 + new SecureRandom().nextInt(54);
for (int i = 0; i < numbers.length; i++)
if(random == numbers[i]) { //随机数与数组的数进行比较,存在相等时重新循环
random = 1 + new SecureRandom().nextInt(54);
i = 0;
}
return random;
}
}