代码:
import java.util.Random; import java.util.Scanner; public class Test03 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String students[] = new String[5]; for (int i = 0;i < students.length;i++){ System.out.print("第" + (i + 1) +"名同学的名字为:"); students[i] = scanner.next(); } for (int i = 0;i < students.length;i++){ System.out.println("第" + (i + 1) + "个同学:" + students[i]); } int rand_num = new Random().nextInt(students.length); System.out.println("第点到名的同学是:" + students[rand_num]); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)