First of all don't know why last task is not passing I have closed all input streams.
And for third task I am getting advice some number might be int. But how that changes things ?
package com.codegym.task.task18.task1820;
/*
Rounding numbers
*/
import java.io.*;
import java.nio.ByteBuffer;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file1 = reader.readLine();
String file2 = reader.readLine();
reader.close();
FileInputStream fileInput1 = new FileInputStream(file1);
FileOutputStream fileOutput2 = new FileOutputStream(file2);
char data = 0;
ArrayList<String> numbers = new ArrayList<>();
String roundedNumbers = "";
while (fileInput1.available() > 0) {
char temp = (char) fileInput1.read();
if (temp != ' ') {
data += temp;
} else {
String tempNum = String.valueOf(data);
numbers.add(tempNum);
data = 0;
}
}
fileInput1.close();
boolean condition = true;
for (String numberNotRounded : numbers) {
double temp = Double.parseDouble(numberNotRounded);
if (condition) {
roundedNumbers += String.valueOf(Math.round(temp));
condition = false;
} else {
roundedNumbers += " " + String.valueOf(Math.round(temp));
}
}
fileOutput2.write(roundedNumbers.getBytes());
fileOutput2.close();
}
}