我想获取 随机数 但是只能是 A类:1 4 8 11 15 18里面的数在吗获取 谁知道?
解决方案 »
- java的一个控制访问类次数的小程序,出现了小错误,跪求各位大侠帮忙哈!!!
- 请帮帮我解决下
- 为什么我的java文件不了
- !!带有文件操作的JAR打包问题!!非常急!!!
- 一个编程问题,欢迎大家提供最优方案
- 如何检测一个数据库连接的断开?
- 需要一个记事本式的程序的源程序
- "B_FundMaster.java": Error #: 360 : unreported exception: java.lang.Exception; must be caught or declared to be thrown at line 6
- 关于RMI客户端无法在IE中运行的问题
- 一个很简单的输出语句,但是结果不太明白
- process 是怎么运行带main函数的class 希望高手提供实例 谢谢
- 关于Integer.parseInt()的问提
把1 4 8 11 15 18放入数组,用i做下标取啊,如果不要重复的可以放入一个HashSet中
int[] arr = { 1, 4, 8, 11, 15, 18 };
int i = (int) (Math.random() * 10 % arr.length);
System.out.println(arr[i]);
import java.util.Random;public class P{
public static void main(String[] args){
int[] a = {1, 4 ,8, 11 ,15 ,18};
Random rand = new Random();
int i;
i = a[rand.nextInt(5)];}
}
你要的 int wanne = intArray[i]
或者List(i)对i进行越界判断.
int[] a = {1, 4 ,8, 11 ,15 ,18};
int s=(int) (Math.random()*a.length);
int i;
i = a[s];
System.out.println(i);