How to realize the number Generator of two-Color Ball Machine by java
This article mainly introduces java how to achieve two-color ball machine number generator, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Double color ball numbers 1: 32 do not repeat 6 (sorted well), choose one of 1: 16 (blue number)
Tool class of import java.util.Random;import java.util.Arrays; / / Operand array / * * @ author Administrator * * / public class Lettery {public static void main (String [] args) {for (int I = 0; I < 5; iTunes +) {int [] nos = create (); / / System.out.println (nos); System.out.println (Arrays.toString (nos)) Choose a note * * @ return * / public static int [] create () {int [] nos = new int [7]; Random r = new Random (); LoopI: for (int I = 0; I < 6;) {nos [I] = r.nextInt (32) + 1 / / Mr. Cheng then compares the current number with the previously generated number to find a repeat for (int j = 0; j < I; Jake +) {if (nos [I] = = nos [j]) {/ / System.out.println ("number" + (I + 1) + "number:" + nos [I] + "and" number + (j + 1) + "); continue LoopI } nos [6] = r.nextInt (16) + 1; Arrays.sort (nos,0,6); / / the first 6 bits of a pair of arrays are sorted by return nos;} public static void printArray (int [] arrays) {for (int I = 0; I < arrays.length; iTunes +) {System.out.print (arrays [I] + ",") Thank you for reading this article carefully. I hope the article "how to realize the two-color ball machine number generator with java" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!