一、双色球问题
package com.lianxi.www; import java.util.Random; import java.util.Scanner; public class 双色球 { public static void main(String[] args) { // 1、随机生成中奖号码。 int[] zhong = new int[7]; zhong = create(); for (int i = 0; i < 7; i++) { System.out.print(zhong[i] + " "); } // 2、玩家输入号码; int[] using = new int[7]; using = user(); // 3、记录前六位数字相同个数。 int count1 = count(zhong, using); // 4、比较蓝色球是否相同。 int flag = 0; if (zhong[6] == using[6]) { flag = 1; } if (flag == 1) { switch (count1) { case 0: case 1: case 2: System.out.println("中了5元。"); break; case 3: System.out.println("中了10元。"); break; case 4: System.out.println("中了200元。"); break; case 5: System.out.println("中了3000元。"); break; case 6: System.out.println("中了1000万元。"); break; } } else if (flag == 0) { switch (count1) { case 1, 2, 3: System.out.println("很遗憾,您并未中奖"); break; case 4: System.out.println("中了10元。"); break; case 5: System.out.println("中了200元。"); break; case 6: System.out.println("中了500万元。"); break; } } } public static int[] create() { int[] arr = new int[7]; Random r = new Random(); for (int i = 0; i < 6;) { int num = r.nextInt(33) + 1; if (!cunzai(arr, num)) { arr[i] = num; i++; } } arr[6] = r.nextInt(16) + 1; return arr; } public static boolean cunzai(int[] arr, int num) { for (int i = 0; i < arr.length - 1; i++) { if (num == arr[i]) { return true; } } return false; } public static int[] user() { int[] using = new int[7]; Scanner sc = new Scanner(System.in); for (int i = 0; i < 6; i++) { int num = sc.nextInt(); using[i] = num; } using[6] = sc.nextInt(); return using; } public static int count(int[] zhong, int[] using) { int count1 = 0; for (int i = 0; i < zhong.length - 1; i++) { if (zhong[i] == using[i]) { count1++; } } return count1; } }
31 29 30 19 33 23 1 31 28 23 16 22 2 3 很遗憾,您并未中奖
标签:case,17,int,System,break,using,out From: https://www.cnblogs.com/zzqq1314/p/17563658.html