1.描述
输入注数,Java随机生成双色球
2.代码
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Scanner;public class Two_color_ball {// 随机生成双色球 前区 01-33 取6个数 后区01-16 取1个数public static void SC() {List<Integer> Front_zone = new ArrayList();Random r = new Random();for (int i = 0; i < 6; i++) {int ran1 = r.nextInt(32) + 1;if (i == 0) {Front_zone.add(ran1);} else {for (int t = 0; t < Front_zone.size(); t++) {if (ran1 == Front_zone.get(t)) {i--;break;} else {if (Front_zone.size() == t + 1) {Front_zone.add(ran1);break;}}}}}List<Integer> Back_zone = new ArrayList();Random r2 = new Random();for (int i = 0; i < 1; i++) {int ran1 = r2.nextInt(15) + 1;if (i == 0) {Back_zone.add(ran1);} else {for (int t = 0; t < Back_zone.size(); t++) {if (ran1 == Back_zone.get(t)) {i--;break;} else {if (Back_zone.size() == t + 1) {Back_zone.add(ran1);break;}}}}}Collections.sort(Front_zone);Collections.sort(Back_zone);System.err.println("祝您喜中头奖!!! 前区:" + Front_zone.toString() + "; 后区:" + Back_zone.toString());}public static void main(String[] args) {System.out.println("请输入购买双色球注数!!!");Scanner in = new Scanner(System.in);int t = in.nextInt();for (int i = 0; i < t; i++) {SC();}}
}
3.效果