当前位置:网站首页>Simulation of two-color ball system to judge the winning situation
Simulation of two-color ball system to judge the winning situation
2022-06-30 15:40:00 【Frog claw white】
Case study

analysis
Analysis on the judgment of winning the prize :
Define a method , Can receive an array of winning numbers , An array of user selected numbers .
Judge the final winning situation according to the number of hit red balls and basketball, and output the details and winning amount .
Code
package com.xxf.casedemo;
import java.util.Random;
import java.util.Scanner;
public class shuangsebog {
public static void main(String[] args) {
// Random 6 A red ball number (1-33 Can't repeat ), Random basketball number (1-16) You can take an array and put it up as the winning number
int[] luckNumber = createLuckNumber();
// Call a method to let the user enter 7 Numbers , Select the number as the user
int[] userNumber = userInputNumber();
judge(luckNumber,userNumber);
}
public static void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + "\t");
}
System.out.println();// Line break
}
public static void judge(int[] luckNumber, int[] userNumber) {
// Judge whether you win the prize
// Definition 2 Variables store the number of red ball hits respectively , And the number of basketball Hits
int redHitNumber = 0;
int blueHitNumber = 0;
// Judge how many red balls you hit , Start Statistics
for (int i = 0; i < userNumber.length - 1; i++) {
for (int j = 0; j < luckNumber.length - 1; j++) {
// Every time we find the equality , It means that the current number hit
if (userNumber == luckNumber) {
redHitNumber++;
break;
}
}
}
// Blue ball number hit
blueHitNumber = luckNumber[6] == userNumber[6] ? 1 : 0;
System.out.println(" The winning number is :");
printArray(luckNumber);
System.out.println(" Betting number is :");
printArray(userNumber);
System.out.println(" How many red balls did you hit :"+redHitNumber);
System.out.println(" Whether you hit the basketball :"+(blueHitNumber==1?" yes ":" no "));
// Judge the winning situation
if (blueHitNumber==1&&redHitNumber<3){
System.out.println(" Congratulations , It's in 5 element !");
}else if(blueHitNumber==1&&redHitNumber==3||blueHitNumber==0&&redHitNumber==4){
System.out.println(" Congratulations , It's in 10 element !");
}else if(blueHitNumber==1&&redHitNumber==4||blueHitNumber==0&&redHitNumber==5) {
System.out.println(" Congratulations , It's in 200 element !");
}else if(blueHitNumber==1&&redHitNumber==5) {
System.out.println(" Congratulations , It's in 3000 element !");
}else if(blueHitNumber==0&&redHitNumber==6) {
System.out.println(" Congratulations , It's in 500 Ten thousand yuan !");
}else if(blueHitNumber==0&&redHitNumber==6) {
System.out.println(" Congratulations , It's in 1000 Ten thousand yuan !");
}
}
public static int[] createLuckNumber() {
// Define a dynamically initialized array , Storage 7 A digital
int[] numbers = new int[7];
// Traversal array , Generate a corresponding number for each location
Random r = new Random();
for (int i = 0; i < numbers.length - 1; i++) {
while (true) {
int data = r.nextInt(33) + 1;
boolean flag = true;
for (int j = 0; j < i; j++) {
if (numbers[j] == data) {
flag = false;
break;
}
}
if (flag) {
numbers[i] = data;
break;
}
}
}
numbers[numbers.length - 1] = r.nextInt(16) + 1;
return numbers;
}
public static int[] userInputNumber() {
// Define an array to store 7 Numbers
int[] numbers = new int[7];
// Let the user type 6 A red ball number
Scanner sc = new Scanner(System.in);
for (int i = 0; i < numbers.length - 1; i++) {
System.out.println(" Please enter the number " + (i + 1) + " A red ball number (1-33, Do not repeat ):");
int data = sc.nextInt();
// Save the currently entered data into the array
numbers[i] = data;
}
// Enter a basketball number separately
System.out.println(" Please enter the basketball number (1-16):");
numbers[6] = sc.nextInt();
return numbers;
}
}
test result

边栏推荐
- N - Is There A Second Way Left? (minimum spanning tree, Kruskal)
- M - smooth engineering continuation (minimum spanning tree)
- 1027 colors in Mars (20 points)
- Technology sharing | anyrtc service single port design
- Chapter III installation and use of jupyter
- Start your global dynamic acceleration journey of Web services in three steps
- B. Moamen and k-subarrays (codeforce+ binary search)
- 1082 read number in Chinese (25 points)
- 开源 STM32 USB-CAN项目
- Imeta | Ye Mao / Shi Yu reviewed the dynamic shuttle and ecological function of intracellular and extracellular genes in the environmental microbiome
猜你喜欢

Create a new MySQL database under Linux and import SQL files

Message queue ten questions

linux下修改mysql密码: ERROR 1396 (HY000): Operation ALTER USER failed for ‘root‘@‘localhost‘

Four solutions to cross domain problems

4.12 input() input function and comments

Advanced C language - pointer 3 - knowledge points sorting

【子矩阵数量统计】CF1181C Flag子矩阵数量统计

FoxPro and I

Industry analysis | the future of real-time audio and video

With as subquery in Oracle
随机推荐
My own opinion on lisp
Scattered knowledge of C language (unfinished)
1077 kuchiguse (20 points)
Modifying MySQL password under Linux: error 1396 (HY000): Operation alter user failed for 'root' @ 'localhost‘
BYD is more and more like Huawei?
Specific steps for installing mysql8.0 on Windows system
B. Moamen and k-subarrays (codeforce+ binary search)
Preliminary study on AI noise reduction evaluation system of sound network
4.12 input() input function and comments
I - constructing roads
Chapter III installation and use of jupyter
1027 colors in Mars (20 points)
Policy Center-User Data
Explain service idempotency design in detail
Map reduce case super detailed explanation
Summary of gradient descent optimizer (rmsprop, momentum, Adam)
1058 a+b in Hogwarts (20 points)
Practical cases of data visualization (timeline rotation diagram, streamlit control year metabase visualization tutorial) 2.0
Zero basic C language learning notes -- first introduction -- 2 data types & variables and constants
K - rochambau (joint search, enumeration)