So I have this recursive method:
public static void returnValues(int i) throws IOException {
double division = (Math.sqrt(inputs.get(i)));
if (i == 0) {
System.out.println(inputs.get(i));
System.out.println("Success! Check your desktop to see the results");
}
else if (division == (int)division) {
System.out.println(inputs.get(i));
i--;
returnValues(i);
}
else {
i--;
returnValues(i);
}
}
Every time you see a System.out.println()
, I need the program to write the value of inputs.get(i)
in a new line of a .txt file. The problem is, every time I try to do so, Java will automatically overwrite the file every time the method calls itself again, so at the end of the execution, the only thing that is written on the file is the output of the last iteration.
Any ideas on how to accomplish this?