Home > Back-end >  Random roll call
Random roll call

Time:10-08

Random roll designed:
1, first create method can store the names of the students into a array;

2, a method can display the student's name; Includes an array of serial number number
3, using the random function to create a method, to obtain a random value (is the student number); By the value of the corresponding student name the student is random order name,
Reference code is as follows, the subsequent code own work
Package cn. Itcast. Lx0310;
import java.util.Scanner;
import java.util.Random;
Public class Randomname {
Public static void main (String [] args) {}
Public static void Addname (String [] stus) {Scanner sc=new Scanner (System. In); for (int i=0; i}
Public static void Displayname (String [] stus) {for (int I=0; i}
}

CodePudding user response:

What effect do you want a program, your tips above code has been almost completed function, as long as in the add a random number, the method of array subscripts, designated by the random number students can achieve random operation, named
Get a Random number of new Random (). NextInt (stus. Length), get a Random integer return, will return to the student's name to complete the integer as a subscript,

CodePudding user response:

1/f, reference source is a ghost reply:
what effect do you want a program, your tips above code has been almost completed function, as long as in the add a random number, the method of array subscripts, designated by the random number students can achieve random operation, named
Get a Random number of new Random (). NextInt (stus. Length), get a Random integer return, will return to the student's name to complete the integer as a subscript,
similar
Storage: 12
Storage: 13
Storage: 14
Point to the named: 13
The

CodePudding user response:

Set up an array or a List, hypothesis of length n
Then directly (int) (Math. The random (0, 1) * n) get to subscript, then direct data [I] or a list. The get (I) access to the corresponding student's name

CodePudding user response:

references a 3-yellow reply: 3/f
set an array or a List, hypothesis of length n
Then directly (int) (Math. The random (0, 1) * n) get to subscript, then direct data [I] or a list. The get (I) access to the corresponding student's name
o
  • Related