Created
October 29, 2016 18:17
-
-
Save alekseytimoshchenko/0705c028b15ca9a6955a8fb2658acb5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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