1 //method One, with a For loop, break out of the statement (not recommended, the method is too stupid, the idea is not very clear)2 3 Public Static voidMain (string[] args) {4 5 //method Two uses the foreach and continue loops and jumps out of the loop6 7 int[] C =New int[7];//Create 7 number series, this place can not define the array8 9Random Ran1 =NewRandom ();//instantiating an objectTen One BooleanBo =false;//define identifiers to control loops A - for(inti = 0; i < c.length; i++) {//generates a random sequence, and one-time judgment is not 0 and there are no identical numbers - the //use the traversal array method to determine if there are duplicate numbers. - - intt = Ran1.nextint (35); - + if(t = = 0) {//Judging if there's 0 this number - +i--; A Continue; at } - for(inty:c) { - - if(Y = =t) { - -Bo =true; in Break; - } to + } - if(bo) { the *i--; $ Continue;Panax Notoginseng } - theC[i] =T; + } A the for(intx1:c) { + -System.out.print (x1 + ""); $ } $ System.out.println (); - - //use Index to determine if there is the same sequence (recommended) the -String str = "";Wuyi the for(inti = 0; I < 7; i++) { - Wu intt = Ran1.nextint (35); - About if(t = = 0) {//Judging if there's 0 this number $ -i--; - Continue; - } A if(Str.indexof (t + "") >= 0) {//to determine if there are duplicate numbers + thei--; - Continue; $ } thestr = str + t + ""; the } the System.out.println (str); the -System.out.println ("------------------"); in the //with replace replacement, this method is simple but not very good, each number is not very random, has not thought of the method of processing the AboutString s = "01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25" the the+ "26 27 28 29 30 31 32 33 34 35";//this way, try not to be too low. the +Random r =NewRandom (); - the for(inti = 0; I < 100; i++) {Bayi intT1 = R.nextint (36); the the if(T1 <= 9) { - -s = S.replace ("0" + T1 + "", ""); the}Else { the thes = s.replace (T1 + "", "" "); the } - the if(S.length () <= 22) { the the System.out.println (s);94 Break; the the } the //There are other methods that haven't been sorted out yet.
Generate non-repeating random numbers (to be perfected)