程序是练出来的

专注JAVA,JavaScript,Python,三剑走天涯。 软素质:忠心、追求、进取、态度、方法、恒心、坚持

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
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();
    }

}

 

posted on 2018-01-13 14:14  爱学习的小象  阅读(157)  评论(0编辑  收藏  举报