Pascal's Triangle Correct Alignment

Hello, I have programmed a proper working Pascal's triangle (numerically). But my alignment is flawed. Basically, the main method repeatedly asks the user to enter an integer, inRow, between 0 and 20 (inclusive). For all those integers inputted, a triangle method will output Pascal's triangle up to inRow th row. But I'm trying to align the triangle so that the leftmost number (the first number in the last row) aligns itself to the extreme left of the screen and builds it self up accordingly.

Also, if I try to get the ouput for 10 rows or over, the sides look like they're curving instead of going straight down.

Here's my code:

class Pascal{

staticfinalint WIDTH = 80;//output width

publicstaticvoid main(String[] args){

//Main method

int inRow;

do{

System.out.println("What is the number of rows in Pascal's Triangle?");

inRow = In.getInt();

if (inRow >= 0 && inRow <= 20){

triangle(inRow);

}

}

while (inRow >= 0);

}

//triangle method (no return value)

publicstaticvoid triangle (int row){

for (int n = 0; n < row; n++){

String output ="" + choose(n,0);//start output string

for (int r = 1; r <= n; r++){

output +=" " + choose(n,r);//attach to output string

}

int gap = (WIDTH - output.length()) / 2;//number of spaces to center

while (gap > 0){

System.out.print(" ");//print one space

gap--;//decrement remaining spaces

}

System.out.println(output);//print output string

}

}//TERMINATE triangle

//choose method

publicstaticlong choose(int n,int r){

int upper, lower;//higher and lower of r and n-r

long result = 1;//initialize result to 1

upper = Math.max(r, n-r);//larger of the bottom two terms

lower = Math.min(r, n-r);//smaller of the bottom two terms

//process the part of n! greater than upper!

for (int i = n; i > upper; i--)

result *= i;//n*(n-1)*...*(n-r+1)

//eliminate lower! from result

for (int i = lower; i > 1; i--)

result /= i;//[n*(n-1)*...*(n-r+1)]/lower/lower-1/.../1

return result;

}//TERMINATE choose

}

[4566 byte] By [terminatorgta] at [2007-10-2 1:47:03]
# 1
where is bbrita and foxyLady?i think one of them (as i recall) posted a solution about this.and where is outawater?
walken16a at 2007-7-15 19:28:13 > top of Java-index,Java Essentials,New To Java...