Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Java code to generate several random numbers of two-color ball

Shulou Source: shulou.com Published: 2022-06-01 12:49:56 09月18日 Update

This article introduces the knowledge of "how to use Java code to generate several random numbers of two-color balls". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Mavan pom file reference dependency

Cn.hutool hutool-all 5.3.6 com.google.guava guava 18.0

Java single-class implementation code, in the editor, paste the following code. Right mouse button, run running

Import cn.hutool.core.util.RandomUtil;import com.google.common.collect.Lists; import java.util.List; / * * @ Author tarzan * @ Date 14:43 on 2021-4-1 * @ Description simulates the two-color ball and randomly generates several residential numbers * / public class DoubleColorBall {/ * main method * * / public static void main (String [] args) {getDoubleColorBallNumber (5) } / * get multi-note two-color ball number * * / public static void getDoubleColorBallNumber (int num) {System.out.println ("randomly generated" + num+ "note two-color ball number is:"); String resultNumber= "; for (int I = 0; I < num; iTunes +) {System.out.println (" ["+ (iTun1) +"] "+ resultNumber+getDoubleColorBallNumber () }} / * get the single-note two-color ball number * * / public static String getDoubleColorBallNumber () {String resultNumber= "; for (int I = 0; I < 6; iTunes +) {String ballNumber= RandomUtil.randomEle (getRedBalls ()) +"; resultNumber=resultNumber+ballNumber;} return resultNumber+RandomUtil.randomEle (getBlueBalls ()) } / * get the collection of red ball numbers * * / public static List getRedBalls () {return getBalls (33);} / * get the collection of blue ball numbers * * / public static List getBlueBalls () {return getBalls (16);} / * get the collection of ball numbers * * / public static List getBalls (int num) {List redBalls= Lists.newArrayList () For (int I = 1; I

Tags: Two-color two-color ball number code generation code generation content more knowledge practicality learning and then dilemma reality situation documents articles methods cases editing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS OPPO Reno MariaDB Redmi