标签:数据存储 ring int get ade blog 产生 dex str
package cn.idcast2; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Random; /*分析: * A、把文本文件中的数据存储到集合中 * B、随机产生一个索引 * C、根据该索引获取一个值 * */ public class Day26 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("a.txt")); ArrayList<String> array = new ArrayList<String>(); String line = null; while ((line = br.readLine()) != null) { array.add(line); } br.close(); //随机产生一个索引 Random r = new Random(); int index = r.nextInt(array.size()); //根据该索引获取一个值 String name = array.get(index); System.out.println("幸运者是:" + name); } }
标签:数据存储 ring int get ade blog 产生 dex str
原文地址:http://www.cnblogs.com/zengjiao/p/6223544.html