go to previous page   go to home page   go to next page

Answer:

Yes. No need to memorize that list of methods.

Example Program

Here is an example program that prints a table of powers of two. The character '\t' is the tab character.

import java.io.*;
import java.util.Scanner;

class PowerTable
{
  public static void main ( String[] args ) 
  {
    // Get filename and create the file
    PrintWriter printer = null;
    Scanner scan = new Scanner( System.in );
    String fileName = "";

    System.out.print("Enter Filename-->");  
    try
    {
      fileName = scan.next();
      
      // create the PrintWriter and enable automatic flushing
      printer = new PrintWriter( new BufferedWriter( new FileWriter( fileName )), true );
    }
    catch ( IOException iox )
    {
      System.out.println("Error in creating file");
      return;
    }
      
    // Write out the table.
    int value = 1;
    printer.println( "Power\tValue"  );
    for ( int pow=0; pow<=20; pow++ )
    {
      printer.print  ( pow   );  
      printer.print  ( '\t'  );  
      printer.println(  value  );  
      value = value*2;
    }
    printer.close();
   
  }
 
}


QUESTION 17:

Instead of using three statements in a row, would the following have worked as well?

out.println( pow + "\t" + value  );