随机抽取名字

读取.txt文档里的名字,随机抽取四个人名

代码:

// An highlighted block import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class NameranList { public static void main(String[] args) throws IOException {try { BufferedReader br = new BufferedReader(new FileReader("文件路径")); List> ls= new ArrayList<>(); while(br.readLine()!=null) { ls.add(br.readLine()); } for(int i =0; i<4; i++) { int r = (int)(Math.random()*ls.size()); System.out.println(ls.remove(r)); }} catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}```取.txt文档里的名字,随机抽取四个人名

    推荐阅读