小练习

import java.util.*;
import java.io.*;


public class ListWords {

private ArrayList<String> al=new ArrayList<String>();
private BufferedReader br;
private BufferedWriter bw;
private String readline;
private String[] strs;

    static {

        System.out.println("He said that's a not a good idea");

    }

     ListWords() {

        try {

            bw=new BufferedWriter(new OutputStreamWriter(System.out));
            br=new BufferedReader(new InputStreamReader(System.in));

        }catch (Exception e) {

            e.getMessage();
        }

     }


     public void getListWords() throws Exception {

         while ((readline=br.readLine())!=null) {

             if (readline.equals("end")) {

                 break;
             }

             strs=readline.split(" ");

             for(String s:strs) {

                 al.add(s);
                 bw.write(s+" ");
                 bw.flush();
             }

             System.out.println(); //换行
         }

         System.out.print("共有"+al.size()+"个单词: ");

          for(String i:al) {

              System.out.print(i+" ");
          }

         bw.close();

     }

    public static void main(String[] args) throws Exception {

        ListWords lw =new ListWords();
        lw.getListWords();
    }

}
原文地址:https://www.cnblogs.com/ltb6w/p/8279035.html