TestWang.java 754 B

1234567891011121314151617181920212223242526
  1. package com.sf;
  2. import java.util.Arrays;
  3. import java.util.Collections;
  4. import java.util.Random;
  5. import java.util.Scanner;
  6. public class TestWang {
  7. public static void main(String[] args) {
  8. Scanner random = new Scanner(System.in);
  9. int number_of_students = random.nextInt(10);
  10. String[] student_names = {"小明", "小红", "小刚", "小李", "小张", "小哈", "小小", "小困", "小顾"};
  11. // 如何把数组转化成list
  12. Collections.shuffle(Arrays.asList(student_names));
  13. // shuffle 洗牌
  14. // {1,2,3,4,5}
  15. // {3,5,1,4,2}
  16. // 取两个
  17. // {3,5}
  18. for (int i = 0; i < number_of_students; i++) {
  19. System.out.println(student_names[i]);
  20. }
  21. }
  22. }