Java_CH10_HW1

  1. import java.io.*;
  2.  
  3. public class Java_CH10_HW1
  4. {
  5. public static void main(String[] args)
  6. {
  7. // TODO 自動產生的方法 Stub
  8. String filepath = "C:\\Users\\Dragonyue\\Desktop\\第 十章作業參考文件\\filewriterdemo1.txt";
  9. try
  10. {
  11. InputStreamReader sr = new InputStreamReader(
  12. new FileInputStream(filepath));
  13. BufferedReader reader = new BufferedReader(sr);
  14. String str = "";
  15. int count = 0;
  16. while ((str = reader.readLine()) != null)
  17. {
  18. int total = 0;
  19. count++;
  20. System.out.println(str);
  21. String[] input = str.split("\t");
  22. for (int i = 0; i < input.length; i++)
  23. total += Integer.parseInt(input[i]);
  24. System.out.println(String.format("第%d列=%d。", count, total));
  25. }
  26. reader.close();
  27. sr.close();
  28. }
  29. catch (IOException e)
  30. {
  31. // TODO 自動產生的 catch 區塊
  32. e.printStackTrace();
  33. }
  34. }
  35. }
  36.  

留言

這個網誌中的熱門文章

C# 井字遊戲