In my online computer science class I have to write a program to determine the surface gravity on each planet in the solar system. I have gotten almost every aspect of it to
Two problems:
1) You are overwriting the file each time. printResultsToFile
should take the whole array, not just one datum. Call it from outside your loop.
2) Consider entering your floating point numbers as 2.08e24 for brevity.
private void printResultsToFile(double result[]) {
PrintWriter pw = new PrintWriter(new FileWriter("planetaryData.txt"));
for (int i=0; i< result.length; i++) {
pw.printf("%.2f%n", result[i]);
}
pw.close();
}