Задача: "The Java Programming Language" Ken Arnold, James Gosling, David Holmes листинги, код, примеры из книги, исходники
Исходник: Глава 15, Ввод-Вывод (Chapter 15. Input-Output), CountSpace class, язык: java [code #173, hits: 12735]
автор: - [добавлен: 12.09.2006]
  1. /**
  2. * Created by IntelliJ IDEA.
  3. * User: me
  4. * Date: 12.09.2006
  5. * Time: 17:23:48
  6. * To change this template use File | Settings | File Templates.
  7. */
  8. import java.io.*;
  9. public class CountSpace {
  10. public static void main(String[] args) throws IOException {
  11. Reader in;
  12. if (args.length == 0)
  13. in = new InputStreamReader(System.in);
  14. else
  15. in = new FileReader(args[0]);
  16.  
  17. int ch;
  18. int total;
  19. int spaces = 0;
  20. for (total = 0; (ch = in.read()) != -1; total++) {
  21. if (Character.isWhitespace((char) ch))
  22. spaces++;
  23. }
  24.  
  25. System.out.println(total + " symbols, " + spaces + " spaces");
  26. }
  27. }
Тестировалось на: java 1.5.0_04

+добавить реализацию