Take a range of different random number

/ * 1. Create an array 
 * 2.For cycle 
 * 3. The number and whether the random number is determined in the same array, if the same random number reacquisition 
 * Get a random number between 10 to 20, the requirements can not be repeated 
 * * / 
public  class the Random {
      public  static  void main (String [] args) {
         Boolean B1 = to true ;
         Double [] dd =   new new  Double [10 ]; 
        dd [ 0] = Math.round ((Math.random () * +. 19. 1 ));
         for ( int J =. 1; J <dd.length; J ++ ) {
             int I = J-. 1 ;
             Double s = Math.round((Math.random()*19+1));
            while (b1==false && i>=0) {
                s = Math.round((Math.random()*19+1));
                if (dd[i]==s) {
                    b1 = false;
                } else {
                    i--;
                }
            }
            dd[j]=s;
        }
        for (int i = 0; i < dd.length; i++) {
            System.out.println(dd[i]);
        }
    }
}

Code is too complex, nested too much

Guess you like

Origin www.cnblogs.com/lkkkk/p/12198435.html