Hey, I am writng a progrma in java to output the pascal triangle.
import TerminalIO.KeyboardReader;
public class TrivialApplication {
public static void main(String args[]) {
KeyboardReader reader = new KeyboardReader();
int integer= reader.readInt("Number of rows: "); //inputs number of rows
int row; //row
int col; //column
for(row=0;row<integer;row++){ //sets the dimensions for rows
for(col=0;col<=row;col++){ //sets the dimensions for columns
System.out.print((factorial(row))/(factorial(col)*factorial(row-col))); //provides formula for creating each row
System.out.print(" "); //adds space for neatness
}
System.out.println(""); //returns a space
}
}
public static int factorial(int n) { //illustrates factorial command
int fact=1;
for(int i=1;i<=n;i++)
fact=fact*i;
return fact;
}
}
I have this so far but it outputs a triangle like
1
1 1
1 2 1
and i need an isoceles triangle. Any help?
import TerminalIO.KeyboardReader;
public class TrivialApplication {
public static void main(String args[]) {
KeyboardReader reader = new KeyboardReader();
int integer= reader.readInt("Number of rows: "); //inputs number of rows
int row; //row
int col; //column
for(row=0;row<integer;row++){ //sets the dimensions for rows
for(col=0;col<=row;col++){ //sets the dimensions for columns
System.out.print((factorial(row))/(factorial(col)*factorial(row-col))); //provides formula for creating each row
System.out.print(" "); //adds space for neatness
}
System.out.println(""); //returns a space
}
}
public static int factorial(int n) { //illustrates factorial command
int fact=1;
for(int i=1;i<=n;i++)
fact=fact*i;
return fact;
}
}
I have this so far but it outputs a triangle like
1
1 1
1 2 1
and i need an isoceles triangle. Any help?