// This file demonstrates writing data to a text file using
// the PrintWriter class and the File class
//
//  -- M. Branicky, 10/09/06, 10/07/07

import java.io.PrintWriter; // needed for output processing using PrintWriter
import java.io.File;        // needed for file input/ouput

public class WriteFile {
  public static void main(String args[]) throws Exception {  // NOTE change here
    // Open the file
    File outfile = new File("out.txt");

    // Create a PrintWriter for file output
    PrintWriter output = new PrintWriter( outfile );

    // Write output to the file
    output.println("Prints an entire line, plus a carriage return.");
    output.print("Prints a string without ... ");
    output.print("a new line ... ");
    output.println("."); // end the line
    output.println();
    output.println("The square root of 2 is " + Math.sqrt(2.0));
    output.printf("The square root of 2 is %f%n", Math.sqrt(2.0));
    output.printf("%d + %d = %d%n", 2, 2, 2+2);
    output.println(2 + " + " + 2 + " = " + (2+2));
    output.println();

    // Close the file
    output.close();
  }
}
