Here is an example program that prints a table of powers of two.
import java.io.*;
class PowerTable
{
public static void main ( String[] args )
{
// Get filename and create the file
PrintWriter out = null;
BufferedReader user = new BufferedReader(
new InputStreamReader( System.in ) );
String fileName = "";
System.out.print("Enter Filename-->"); System.out.flush();
try
{
fileName = user.readLine().trim();
// create the PrintWriter and enable automatic flushing
out = 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;
out.println( "Power\tValue" );
for ( int pow=0; pow<=20; pow++ )
{
out.print ( pow );
out.print ( '\t' );
out.println( value );
value = value*2;
}
out.close();
}
}
The character '\t' is the tab character.