Created
August 29, 2017 13:46
-
-
Save ihopeudie/727bc69d32ab17c64fa064df31431def 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.task.task18.task1817; | |
/* | |
Пробелы javarush | |
В метод main первым параметром приходит имя файла. | |
Вывести на экран соотношение количества пробелов к количеству всех символов. Например, 10.45. | |
1. Посчитать количество всех символов. | |
2. Посчитать количество пробелов. | |
3. Вывести на экран п2/п1*100, округлив до 2 знаков после запятой. | |
4. Закрыть потоки. | |
*/ | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.util.Locale; | |
import static java.util.Locale.*; | |
public class Solution { | |
public static void main(String[] args) throws IOException { | |
FileInputStream iStream = new FileInputStream(args[0]); | |
int n = iStream.available(); | |
byte[] array = new byte[n]; | |
iStream.read(array); | |
iStream.close(); | |
int counter = 0; | |
for (byte element: array | |
) { | |
if (element == ' ') counter++; | |
} | |
System.out.println(String.format(Locale.ENGLISH,"%(.2f",(double)counter/n*100)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment