本帖最后由 yikwing 于 2016-5-16 23:43 编辑
- /**
- * Created by yikwing on 2016/5/15.
- */
- import java.util.*;
- class lottery {
- public static void main(String[] args) {
- arrTools at = new arrTools(); //引入外界方法arrTools
- int[] sysRedBall = new int[6]; //定义系统红球数组
- int sysBlueBall = 0; //定义系统蓝球
- int[] userRedBall = new int[6]; //定义系统蓝球数组
- int userBlueBall = 0; //定义系统蓝球
- int redCount = 0; //正确的红球个数
- int blueCount = 0; //正确的蓝球个数
- Random r = new Random();
- int[] redBall = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33};
- int index = 0; //定义数组下标
- //生成系统红球
- for (int i = 0; i < sysRedBall.length; i++) {
- while (true) {
- index = r.nextInt(33);
- if (redBall[index] != -1) {
- sysRedBall[i] = redBall[index];
- redBall[index] = -1;
- break;
- }
- }
- }
- at.kuaisu(sysRedBall); //使用外界方法(快速排序)数组
- //生成系统蓝球
- sysBlueBall = r.nextInt(16) + 1;
- //接收用户红球
- System.out.println("红球");
- Scanner in = new Scanner(System.in);
- for (int i = 0; i < userRedBall.length; i++) {
- userRedBall[i] = in.nextInt();
- }
- at.kuaisu(userRedBall);
- //接收用户蓝球
- System.out.println("蓝球");
- userBlueBall = in.nextInt();
- //验证是否中奖
- for (int i = 0; i < sysRedBall.length; i++) {
- for (int j = 0; j < userRedBall.length; j++) {
- if (sysRedBall[i] == userRedBall[j]) {
- redCount++;
- break;
- }
- }
- }
- if (sysBlueBall == userBlueBall) {
- blueCount++;
- }
- //判断是否中奖
- System.out.print("系统红球为: ");
- at.PrintArray(sysRedBall); //调用外界方法(遍历数组)
- System.out.println("系统蓝球为: " + sysBlueBall);
- System.out.println("-----------------------------------------------");
- System.out.print("您购买红球为: ");
- at.PrintArray(userRedBall); //调用外界方法(遍历数组)
- System.out.println("您购买蓝球为: " + userBlueBall);
- System.out.println("-----------------------------------------------");
- System.out.println("你的红球中奖数目为: " + redCount);
- System.out.println("你的蓝球中奖数目为: " + blueCount);
- if (redCount == 6 && blueCount == 1) {
- System.out.println("一等奖,恭喜中一百万");
- } else if (redCount == 6) {
- System.out.println("二等奖,恭喜中三十万");
- } else if (redCount == 5 && blueCount == 1) {
- System.out.println("三等奖,恭喜中九十万");
- } else if (redCount == 5 || redCount == 4 && blueCount == 1) {
- System.out.println("四等奖,恭喜中二十万");
- } else if (redCount == 4 || redCount == 3 && blueCount == 1) {
- System.out.println("五等奖,恭喜中一万");
- } else if (blueCount == 1) {
- System.out.println("六等奖,恭喜中十块");
- } else {
- System.out.println("很遗憾您没有获奖,感谢您的参与.");
- }
- }
- }
复制代码
|
|