I have correct output in my file2 but codegym doesn;t accept 2 requirments..please help...
package com.codegym.task.task18.task1820;
/*
Rounding numbers
*/
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
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 stream1 = new FileInputStream(file1);
FileOutputStream stream2 = new FileOutputStream(file2, true);
ArrayList<Integer> list = new ArrayList<>();
while(stream1.available() > 0) {
int current = stream1.read();
if(current != 32){
list.add(current);
} else {
int index_1 = list.get(0);
char index_2 = (char) index_1;
String index_3 = Character.toString(index_2);
for(int i = 1; i < list.size(); i++){
index_1 = list.get(i);
index_2 = (char) index_1;
index_3 += Character.toString(index_2);
}
double indexInt = Double.parseDouble(index_3);
int round = (int) Math.round(indexInt);
String x = Integer.toString(round);
byte[] bytes = x.getBytes();
stream2.write(bytes);
stream2.write(32);
list.removeAll(list);
}
}
stream1.close();
stream2.close();
}
}
//1. The program should read a file name twice from the console.
//2. Create an input stream for the first file. Create an output stream for the second file.
//3. Read the numbers from the first file, round them, and write them to the second file, separated by spaces.
//4. The rounding must be performed as indicated in the task.
//5. The file streams must be closed.