JAVA算法学习之杨辉三角
public class YHSJ {
/**
* @param args
* @createtime Apr 14, 2010 6:49:41 PM
*/
public static void main(String[] args) {
Integer[] topRow = null;
Integer[] currentRow = null;
for(int i=0;i<10;i++) {
currentRow = new Integer[i+1];
for(int j=0;j<i+1;j++) {
try {
currentRow[j] = (topRow[j-1]+topRow[j]);
} catch (Exception e) {
currentRow[j] = 1;
}
System.out.print(currentRow[j]+" ");
}
System.out.println();
topRow = currentRow;
}
}
}