用java编写,模仿福利彩票23选5,随机生成5个不同的1~23的整数

如题所述

/**
 * 生成指定个数的小于指定最大值的随机数,并存放在list中返回
 * 
 * @param length
 *            生成数的个数
 * @param max
 *            最大值
 * @return
 */
public static List<Integer> getRedRandomList(int length, int max) {
List<Integer> list = new ArrayList<Integer>();
while (list.size() < length) {
int ran = 0;
ran = (int) (Math.random() * 100);
if (!(ran == 0)) {
if (ran < max) {
if (list.size() == 0) {
list.add(ran);
} else {
if (!list.contains(ran)) {
list.add(ran);
}
}
} else {
ran = ran / 3;
if (!(ran == 0)) {
if (list.size() == 0) {
list.add(ran);
} else {
if (!list.contains(ran)) {
list.add(ran);
}
}
}
}
}
}
return list;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-10-23
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomTest {
public static void main(String[] args) {
List<Integer> resultList = new ArrayList<Integer>();
Random r = new Random();
while (true) {
int num = r.nextInt(23) + 1;
if (!resultList.contains(num))
resultList.add(num);
if (resultList.size() >= 5)
break;
}
System.out.println(resultList);
}
}

本回答被网友采纳
第2个回答  2020-02-03
这是两个电容,互不相连。即是把两个电容装在同一盒内。一般同一侧是一组,另一侧是第二组。 1.可以对初认定一组电容充放电试验。若见到有充放电功能,就可认定这两电极是为一个电容器的两接脚。若没有充放电现象就认定不是同一组的两个电极。 2.外上方法,定能快速找到两组电容器的各自两电极接脚 3.一般可以用万用表电阻档两表笔进行。
相似回答