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 is the result: