import java.util.Random;
import java.util.Scanner;
public class CallName1{
public static void main(String[] args) {
System.out.println("--------随机点名器--------");
String[] students = new String[3];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < students.length; i++) {
System.out.println("存储第"+i+"个名称:");
students[i] = sc.next();
}
for (int i = 0; i < students.length; i++) {
//String name = students[i];
//打印同学名字
System.out.println("第"+i+"个学生名称:" + students[i]);
}
int index = new Random().nextInt(students.length);
//Random ran= new Random();
//int index = ran.nextInt(students.length);
//String name = students[index];
System.out.println(students[index]);
}
}
|
|