java怎么在几个数字中随机取出一个
展开全部
import java.util.Random;
public class RandomNumber {
public static void main(String[] args) {
int []numbers = {1,2,5,4,3,42,71,25,6};
Random random = new Random();
int index = random.nextInt(numbers.length);
System.out.println(numbers[index]);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询