Tables for Command prompt in java?

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
I need to find something regarding creating tables in java. My CS teacher gave one example in a program, but its not documented at all, and is pretty confusing and uses many other methods too so you have to flip through tons of pages and files.

I need to create tables (Is this possibly in the command prompt) with numbers in each one.

Mods: Its in OT because I'd appreciate an answer soon
 

AgaBoogaBoo

Lifer
Feb 16, 2003
26,108
5
81
Originally posted by: Ameesh
tables?

do you mean a 2d array or a hashtable?

I guess it would be a 2d array. Ntohing complicated here, just a 5x5 table so that all entires are lined up and its easy to read.
 

EyeMWing

Banned
Jun 13, 2003
15,670
1
0
I BELIEVE Java has a Format class built in. That's how I've done my tables. You can use this for alignment.

Sample (This draws a multiplication table)


//Multiplication table
public void printTable(int x, int y)
{
//Print table's upper left corner - vacant space.
System.out.print(Format.right("X|",5));
//Print top row of numbers
for (int cX=1; cX<=x; cX++)
{
System.out.print(Format.right(cX,5));
}
System.out.println();
//Print line dividing top row from table
System.out.print(Format.right("----+",5));
for (int cX=1; cX<=x; cX++)
{
System.out.print(Format.right("-----",5));

}
System.out.println();
//Into table body here
for (int cY=1; cY<=y; cY++)
{
//Print left column and dividing bar
System.out.print(Format.right(cY,4)+"|");
for (int cX=1; cX<=x; cX++)
{
System.out.print(Format.right(cX*cY,5));
}
System.out.println();
}
}