I am working on a java program concerning the pascal's triangle.
So this is how it is coded:
for(int i = 0; i < 5; i++){
for(int j = 0, x = 1; j <= i; j++){
System.out.print(x + " ");
x = x * (i - j) / (j + 1);
}
System.out.println();
}
and it shows:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
But when I tried to change the code to:
for(int i = 0; i < 5; i++){
for(int j = 0, x = 1; j <= i; j++){
System.out.print(x + " ");
x *= (i - j) / (j + 1);
}
System.out.println();
}
and as you may have noticed, only the operator has changed to *=, but the result is:
1
1 1
1 2 0
1 3 3 0
1 4 4 0 0
Any idea what must have happened? Thanks in advance!