I can't find the error's in this program. I had to create these methods and must use them. It's for my high school class and I've cut 19 errors to one.
Code:
import java.util.Scanner;
public class Pascal{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
int rows = getRows();
while (rows != 0){
printTriangle(rows);
rows = getRows();
}
}
public static long factorial(long n)
{
//A number that is leading up to the specified number
for (int i=2,k=1; i<=n; i++){
k*=i;
return k;
}
return 1;
}
public static int getRows(){
Scanner input= new Scanner(System.in);
int rows=5;
System.out.println("Please enter the number of rows:");
rows = input.nextInt();
return (rows);
}
public static long nCr(long n, long r){
return factorial(n)/factorial(r)*(factorial (n-r));
}
public static void printTriangle(int r){
for (int i=1;i<=r;i++)
{
for(int j=1;j<=i; j++)
{
System.out.println(nCr(i-1,j-1));
}
System.out.println("");
}
}
}