Advertisement
jaVer404

level18.lesson10.home01

Nov 5th, 2015
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package com.javarush.test.level18.lesson10.home01;
  2.  
  3. /* Английские буквы
  4. В метод main первым параметром приходит имя файла.
  5. Посчитать количество букв английского алфавита, которое есть в этом файле.
  6. Вывести на экран число (количество букв)
  7. Закрыть потоки. Не использовать try-with-resources
  8. */
  9.  
  10. import java.io.FileInputStream;
  11. import java.io.IOException;
  12.  
  13. public class Solution {
  14.     public static void main(String[] args) throws IOException {
  15.         FileInputStream fileInputStream = new FileInputStream(args[0]);
  16.         char tempChar;
  17.         int counter = 0;
  18.         while (fileInputStream.available()>0) {
  19.             tempChar = (char)fileInputStream.read();
  20.             if ((tempChar >= 'a' && tempChar <= 'z') || (tempChar >= 'A' && tempChar <= 'Z')) {
  21.                 counter++;
  22.             }
  23.         }
  24.         System.out.println(counter);
  25.         fileInputStream.close();
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement