본문을 한글로만 쓰면 트랙백이 안되는구나
한글 조금 써도 안되네.. 뭐지?
package babosamo.tistory;
public class TriangleOfPascal {
static final int InitNumber = 1;
public static void main(String[] args) {
final int Depth = 6; //input test value
int[][] result = calPascalArray(Depth);
printPascalArray(result);
}
private static int[][] calPascalArray(int depth){
int[][] result = new int[depth][];
int[] first = {InitNumber};
result[0] = first; // depth == 0
for(int i = 1; i < depth ; i ++){
int[] tempArray = new int[i + 1];
tempArray[0] = InitNumber; // first Value
tempArray[tempArray.length - 1] = InitNumber; // last Value
for(int y = 1; y < result[i - 1].length ; y ++){
tempArray[y] = result[i -1][y -1] + result[i -1][y];
}
result[i] = tempArray;
}
return result;
}
private static void printPascalArray(int[][] result){
for(int i = 0; i < result.length; i ++){
int[] tempArray = result[i];
int length = tempArray.length;
System.out.print("depth: " + i + " === ");
for(int y = 0; y < tempArray.length; y++){
System.out.print(tempArray[y] + " ");
}
System.out.println();
}
}
}