Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alekseytimoshchenko/0705c028b15ca9a6955a8fb2658acb5b to your computer and use it in GitHub Desktop.
Save alekseytimoshchenko/0705c028b15ca9a6955a8fb2658acb5b to your computer and use it in GitHub Desktop.
package com.javarush.test.level18.lesson05.task02;
/* Подсчет запятых
С консоли считать имя файла
Посчитать в файле количество символов ',', количество вывести на консоль
Закрыть потоки. Не использовать try-with-resources
Подсказка: нужно сравнивать с ascii-кодом символа ','
*/
import java.io.*;
import java.util.concurrent.atomic.AtomicInteger;
public class Solution {
public static void main(String[] args) throws IOException
{
int sing = 44;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String fileName = br.readLine();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName));
AtomicInteger count = new AtomicInteger();
while (bis.available() > 0){
if (bis.read() == sing){
count.incrementAndGet();
}
}
br.close();
bis.close();
System.out.println(count.get());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment