I have gone through multiple times and it seems fine to me.
The only thing that MAYBE is not ok is that I add a space even at the end of the new file where I write the rounded numbers. But it doesn't say anywhere that there shouldn't be a space after the last number.
Anyway, what is the problem? I can't figure it out?
package com.codegym.task.task18.task1820;
/*
Rounding numbers
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String fileName1 = br.readLine();
String fileName2 = br.readLine();
br.close();
FileInputStream fractionalNumbers = new FileInputStream(fileName1);
FileOutputStream roundedNumbers = new FileOutputStream(fileName2);
String numbersAndSpacesString = "";
//read all of the initial numbers (including spaces into a String);
while (fractionalNumbers.available() > 0){
numbersAndSpacesString += Integer.toString(fractionalNumbers.read());
}
//use split
String [] numbers = numbersAndSpacesString.split("32");
int [] numbersRounded= new int[numbers.length];
//round them
for (int i = 0; i < numbers.length; i++){
numbersRounded[i] = (int) Math.round(Double.parseDouble(numbers[i]));
roundedNumbers.write(numbersRounded[i]);
roundedNumbers.write(32);
}
fractionalNumbers.close();
roundedNumbers.close();
}
}