In a small class, of all people, randomly selected person to answer a question, and the question the same person can not be repeated

Moth.JUL.JUL04 Package; 

Import java.util.Scanner; 

// 12 people, a person cyclic random questions, questions so far until all finished, is not required to repeat the question one 
public  class the Random {
     static Scanner INPUT = new new Scanner (. the System in ); 

    public  static  void main (String [] args) { 
        String names [] = { " acridine a " , " acridine two " , " acridine three " , " acridine four " , " acridine five " , " acridine six " , "Acridine seven" , " Acridine eight " , " acridine nine " , " acridine ten " , " acridine eleven " , " acridine twelve " }; 
        . System OUT .println ( " start random questions! " ); 
        String ST = " " ; // loop condition 
        int index = - . 1 ; // identifies the person asking the question subscripts 
        do {
             // random number of type int num used to receive the generated 
            int num = ( int ) (the Math.random() * 12 + 0 );
             IF ! (Names [NUM] = null ) { 
                . System OUT .println ( " questions begin, " + names [NUM] + " to answer questions! " );
                 // Question finished removing this person 
                index = NUM; 
                names [index] = null ; 
                . the System OUT .println ( " continue question (n-/ Y): " ); 
                ST = input.next ();
                 // traverse the array elements, if the array elements are all null boo is false
                boolean boo = false;
                for (int i = 0; i < names.length; i++) {
                    if (names[i] != null) {
                        boo = true;
                    }
                }
                if (!boo) {
                    System.out.println("已经提问完所有人!");
                    break;
                }
            }
        } while ("Y " .equals (ST)); 
        . the System OUT .println ( " End Program! " ); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/zeng1997/p/11130303.html