Что не так делаю?
Я его обрезаю до 2 знаков, но почему неТ?
package com.javarush.task.task18.task1817;
import java.io.*;
import java.util.ArrayList;
/*
Пробелы
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[0])));
ArrayList<String> file = new ArrayList<>();
while (reader.ready()) {
file.add(reader.readLine());
}
reader.close();
int count = 0;
int count_space = 0;
for (int i = 0; i < file.size(); i++) {
count += file.get(i).length();
}
for (int i = 0; i < file.size(); i++) {
char[] chars = file.get(i).toCharArray();
for (int j = 0; j < chars.length; j++) {
if (chars[j] == ' ') {
count_space++;
}
}
}
double dob = (double) count_space/count*100;
String s = String.valueOf(dob);
if (s.length() >= s.indexOf('.')+3) {
s = s.substring(0,s.indexOf('.')+3);
}
dob = Double.parseDouble(s);
System.out.println(dob);
}
}