双色球代码

  1 package xuexi;
  2 // 43.44行 有惊喜
  3 import java.util.Arrays;
  4 import java.util.Random;
  5 import java.util.Scanner;
  6 
  7 public class SS {
  8 
  9     /**
 10      * 1、生成系统随机号码 6红 1蓝 2、接收用户选号 6红1蓝 3、验证号码正确个数 4、公布中奖结果
 11      * 
 12      * @author Administrator
 13      *
 14      */
 15 
 16     public static void main(String[] args) {
 17         int[] xh = new int[6];// 存储系统生成的红球
 18         int xl = 0; // 存储系统生成的篮球
 19         int[] wh = new int[6]; // 玩家选择的红球
 20         int wl = 0; // 玩家选择的篮球
 21         int zh = 0; // 正确的红球个数
 22         int zl = 0; // 正确的篮球个数
 23         Random r = new Random(); // 定义数组
 24         int[] rb = { 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,
 25                 28, 29, 30, 31, 32, 33 };// 规定数组的范围
 26         // 游戏开始
 27         System.out.println("双色球游戏开始,祝你好运");
 28         int a = 0;// 临时变量
 29 
 30         // 生成系统号码
 31         for (int i = 0; i < xh.length; i++) {// 设置一个循环
 32             while (true) {
 33                 a = r.nextInt(33);// 抽取随机数字
 34                 if (rb[a] != 0) {
 35                     xh[i] = rb[a];
 36                     rb[a] = 0;
 37                     break;
 38                 }
 39             }
 40         }
 41         xl = r.nextInt(16) + 1;
 42 
 43         //    System.out.println(Arrays.toString(xh) + "系统红色球");
 44         //    System.out.println(xl + "系统蓝色球");
 45         
 46         
 47         // 接收用户选号
 48         System.out.println("请选择红球号码;(1-33) 请输入:");
 49         Scanner in = new Scanner(System.in);
 50 
 51         for (int i = 0; i < wh.length; i++) {
 52 
 53             wh[i] = in.nextInt();
 54         }
 55 
 56         System.out.println("请选择蓝球号码;(1-16) 请输入:");
 57         wl = in.nextInt();
 58 
 59         // 验证是否中奖
 60 
 61         for (int i = 0; i < xh.length; i++) {// 验证系统红i球
 62             for (int j = 0; j < wh.length; j++) {// 玩家 选择的红球
 63                 if (xh[i] == wh[i]) {
 64                     zh++;
 65                 }
 66                 break;
 67             }
 68 
 69         }
 70 
 71         if (xh == wh) {
 72             zl++;
 73 
 74         }
 75 
 76         if (xl == wl) {
 77             zl = 1;
 78         } else {
 79             zl = 0;
 80         }
 81 
 82         // 判断是否中奖
 83         if (zh == 6 & zl == 1) {
 84             System.out.println("恭喜你 中了一等奖500万");
 85         } else if (zh == 6 & zl == 0) {
 86             System.out.println("恭喜你 中了二等奖10万");
 87         } else if (zh == 5 & zl == 1) {
 88             System.out.println("恭喜你 中了三等奖3000");
 89         } else if (zh == 5 || (zh == 4 && zl == 1)) {
 90             System.out.println("恭喜你 中了四等奖200");
 91         } else if (zh == 4 || (zh == 3 && zl == 1)) {
 92             System.out.println("恭喜你 中了五等奖10");
 93         } else if (zl == 1) {
 94             System.out.println("恭喜你 中了六等奖5");
 95         } else {
 96             System.out.println("谢谢参与");
 97         }
 98         // 输出结果
 99         System.out.print("本期红球号码为:");
100         for (int i = 0; i < xh.length - 1; i++) {
101             for (int j = 0; j < xh.length - 1 - i; j++) {
102                 if (xh[j] > xh[j + 1]) {
103                     int t = xh[j];
104                     xh[j] = xh[j + 1];
105                     xh[j + 1] = t;
106 
107                 }
108             }
109         }
110         System.out.print("本期红球号码为:");
111         for (int i = 0; i < xh.length; i++) {
112 
113             System.out.print(xh[i] + " ");
114         }
115         System.out.println("");
116         System.out.print("本期篮球号码为:" + xl);
117         for (int i = 0; i < xh.length; i++) {
118 
119         }
120     }
121 
122 }
双色球测试完毕

我咋就没这么好的命啊。

原文地址:https://www.cnblogs.com/zjy954/p/5024655.html