- i'm facing an error on my pascal triangle, but i don't know whether it's java or my code which is the problem. here is the code:
import java.util.Scanner;
public class sdz {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int levels;
levels = sc.nextInt();
for(int i = 0; i <= levels; i++){
for(int j =0; j <= i; j++){
System.out.print(combinatorial(i,j) + " ");
}
System.out.println();
}
}
static int fact(int n ){
if(n > 0)
return n * fact(n-1);
else
return 1;
}
static int combinatorial(int n , int r){
return fact(n)/(fact(r) * fact(n-r));
}
}
When i input the level to 13 it fails here's the result The loop at 13