Pascal's triangle: Difference between revisions

added a different implementation to the Java solutions.
(added a different implementation to the Java solutions.)
Line 1,109:
}
}</lang>
 
===Using arithmetic calculation of each row element ===
This method is limited to 30 rows because of the limits of integer calculations (probably when calculating the multiplication). If m is declared as long then 62 rows can be printed.
<lang java>
public class Pascal {
private static void printPascalLine (int n) {
if (n < 1)
return;
int m = 1;
System.out.print("1 ");
for (int j=1; j<n; j++) {
m = m * (n-j)/j;
System.out.print(m);
System.out.print(" ");
}
System.out.println();
}
public static void printPascal (int nRows) {
for(int i=1; i<=nRows; i++)
printPascalLine(i);
}
}
</lang>
 
=={{header|JavaScript}}==
Anonymous user