@Sarah
2015-11-05T17:52:25.000000Z
字数 1697
阅读 1999
java笔记
上次课的作业更改后
//读取六级单词内容并加进数组import java.io.*;import java.util.*;public class ReadWords {public static void main(String[] args) throws Exception {FileReader sf= new FileReader("六级词库副本.txt");BufferedReader br = new BufferedReader(sf);List<String> ewords=new ArrayList<String>();List<String> cwords=new ArrayList<String>();while(true){String s=br.readLine();if(s!=null){if(s.startsWith("[ "))cwords.add(br.readLine());else if(s.trim().length()!=0)ewords.add(s);}elsebreak;}//System.out.println(ewords.get(0)+"\t"+cwords.get(0));BufferedReader kr=new BufferedReader(new InputStreamReader(System.in));while(true){int i=(int)(Math.random()*ewords.size());System.out.println(cwords.get(i));System.out.print(":");String s=kr.readLine();if(s.equals(ewords.get(i)))System.out.println("OK!");elseSystem.out.println("error:"+ewords.get(i));System.out.print("continue?(y/n)");if(kr.readLine().equals("n"))break;}}public static void main2(String[] args) throws Exception {FileReader sf= new FileReader("六级.txt");BufferedReader br = new BufferedReader(sf);List<String> al=new ArrayList<String>();while(true){String s=br.readLine();if(s!=null)al.add(s);else {break;}}System.out.println(al.contains("adhere"));System.out.println(al.get(10));System.out.println(al.get(11));al.remove(10);System.out.println(al.get(10));al.clear();System.out.println(al.size());}//读取六级单词内容并加入数组里public static void main1(String[] args) {try {int i= 0;FileReader s = new FileReader("六级.txt");BufferedReader br = new BufferedReader(s);String[] words= new String[9000];while (true) {words[i] = br.readLine();if (words[i]==null)break;i++;}s.close();System.out.println(i);System.out.println(words[(int)(i*Math.random())]);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}