Advertisement
jaVer404

level18.lesson05.task02

Nov 3rd, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package com.javarush.test.level18.lesson05.task02;
  2.  
  3. /* Подсчет запятых
  4. С консоли считать имя файла
  5. Посчитать в файле количество символов ',', количество вывести на консоль
  6. Закрыть потоки. Не использовать try-with-resources
  7.  
  8. Подсказка: нужно сравнивать с ascii-кодом символа ',' 054
  9. */
  10.  
  11. import java.io.*;
  12.  
  13. public class Solution {
  14.     public static void main(String[] args) throws IOException{
  15.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  16.         String fileName = reader.readLine();
  17.  
  18.         FileInputStream inputStream = new FileInputStream(fileName);
  19.         int counter=0;
  20.         while (inputStream.available()>0) {
  21.             if (inputStream.read()==44) {
  22.                 counter++;
  23.             }
  24.         }
  25.         reader.close();
  26.         inputStream.close();
  27.         System.out.println(counter);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement