当前位置:网站首页>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

边栏推荐
- iMeta | 叶茂/时玉等综述环境微生物组中胞内与胞外基因的动态穿梭与生态功能...
- 深入理解.Net中的线程同步之构造模式(二)内核模式1.内核模式构造物Event事件
- I - constructing roads
- Technology sharing | how to quickly realize audio and video online calls
- Pycharm----xx. So cannot open shared object file problem solving
- 1035 password (20 points)
- 1107 social clusters (30 points)
- K - or unblocked project (minimum spanning tree)
- 1076 forwards on Weibo (30 points)
- Kubernetes: a comprehensive analysis of container choreography
猜你喜欢

Oracle中的With As 子查询

各省GDP可视化案列,附带csv Metabase处理

At the beginning of the 2022 new year, I will send you hundreds of dry articles

C language foundation - pointer array - initialization method & constant pointer array, pointer constant array

Kubernetes: a comprehensive analysis of container choreography

Is Domain Driven Design (DDD) reliable?

《你的灯亮着吗》开始解决问题前,得先知道“真问题”是什么

FoxPro and I

Tetris source code (color version)

Technology sharing | how to quickly realize audio and video online calls
随机推荐
Policy Center > Google Play‘s Target API Level Policy
At the beginning of the 2022 new year, I will send you hundreds of dry articles
On which platform is it safer to buy Treasury reverse repo?
B. Moamen and k-subarrays (codeforce+ binary search)
4.6 floating point number
Alibaba cloud OSS object storage cross domain settings
开源 STM32 USB-CAN项目
1018 public bike Management (30 points)
Voice codec based on machine learning Agora silver: support high quality voice interaction at ultra-low bit rate
国债逆回购在哪个平台上买比较安全?
Chapter 2 installation and use of vscode editor
About pickle module - 6 points that beginners must know
001 data type [basic]
1062 talent and virtue (25 points)
Joint examination for management -- sample composition
1148 werewolf - Simple Version (20 points)
Map reduce case super detailed explanation
数据治理市场:亿信华辰朝左,华傲数据向右
E - highways (minimum spanning tree)
RTC monthly tabloid programming challenge ended successfully in June; Review of the first anniversary of sound network's listing