Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level18.lesson05.task02;
- /* Подсчет запятых
- С консоли считать имя файла
- Посчитать в файле количество символов ',', количество вывести на консоль
- Закрыть потоки. Не использовать try-with-resources
- Подсказка: нужно сравнивать с ascii-кодом символа ',' 054
- */
- import java.io.*;
- public class Solution {
- public static void main(String[] args) throws IOException{
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String fileName = reader.readLine();
- FileInputStream inputStream = new FileInputStream(fileName);
- int counter=0;
- while (inputStream.available()>0) {
- if (inputStream.read()==44) {
- counter++;
- }
- }
- reader.close();
- inputStream.close();
- System.out.println(counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement