import java.io.PrintStream; import java.io.FileNotFoundException; /** FileOutput.java - What if the output can't all fit on the screen? */ public class FileOutput { public static void main(String [] args) throws FileNotFoundException { // Create the output file. PrintStream out = new PrintStream("output.txt"); // Print to both the screen AND to the output file. for (int i = 50; i <= 1250; i += 5) { System.out.printf("The square root of %4d is %6.3f\n", i, Math.sqrt(i)); out.printf("The square root of %4d is %6.3f\n", i, Math.sqrt(i)); } // Always close the file! out.close(); } }