当前位置:网站首页>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
边栏推荐
- from Crypto. Cipher import AES could not find the solution record with module error
- Alibaba cloud OSS object storage cross domain settings
- 1030 travel plan (30 points)
- Imitating freecodecamp to build a programming ability test platform
- 数数据可视化实战案例(timeline轮播图,streamlit 控件年份 metabase可视化使用教程)2.0
- 001 basic knowledge (unfinished)
- O - ACM contest and blackout (minimum spanning tree, Kruskal)
- ADB devices cannot detect the problem of Xiaomi note 3
- Policy Center > Deceptive Behavior
- Jupyter notebook basic knowledge learning
猜你喜欢
Webrtc: industrial application based on Internet of things
Modifying MySQL password under Linux: error 1396 (HY000): Operation alter user failed for 'root' @ 'localhost‘
The short video and live broadcast incubation training camp with goods opens nationwide enrollment!
Rte2021 review of the practice and the way of AI OPS landing
Compare whether the two arrays are the same
map reduce案例超详细讲解
4.2 escape characters
The crystal ball "data insight" was officially launched: insight into the change of consumption trend and the details of interactive experience
Web technology sharing | whiteboard toolbar encapsulation of Web
How should we understand the variability of architecture design?
随机推荐
各省GDP可视化案列,附带csv Metabase处理
Kubernetes: a comprehensive analysis of container choreography
The sound network has fully opened the real-time transmission network sd-rtn, which has been free of network wide accidents for seven years - this is FPA!
终于看懂科学了!200张图领略人类智慧的巅峰
Soap comparison result file description
Expressions in if statements
4.5 integer
1018 public bike Management (30 points)
Chapter III installation and use of jupyter
1105 spiral matrix (25 points)
At the beginning of the 2022 new year, I will send you hundreds of dry articles
Imeta | Ye Mao / Shi Yu reviewed the dynamic shuttle and ecological function of intracellular and extracellular genes in the environmental microbiome
[sub matrix quantity statistics] cf1181c flag sub matrix quantity statistics
A. Theatre Square(codefore)
Review 2021, embrace change and live up to Shaohua
Fundamentals of C language -- similarities and differences between arrays and pointers
Zero basic C language learning notes -- first introduction -- 2 data types & variables and constants
Policy Center > Device and Network Abuse
Single cycle CPU of the design group of West University of Technology
E - highways (minimum spanning tree)