综合

杨辉三角 学习笔记

导读: 
package com.ctgu.java.exer;

public class TestYangHui {
	public static void main(String[] args){
		int[][] yangHui = new int[13][];
		for(int i = 0;i < yangHui.length;i++){
			yangHui[i] = new int[i+1];
		}
		for(int i = 0; i <yangHui.length;i++){
			for(int j = 0;j < yangHui[i].length;j++){
			yangHui[i][0] = yangHui[i][i]=1;
			
			if(i>1 && j >0 && j <i){
				yangHui[i][j] = yangHui[i-1][j] + yangHui[i-1][j-1];
			}
		  }
			
		}

	
		
		
		for(int i = 0 ;i <yangHui.length;i++){
			for(int j = 0; j < yangHui[i].length;j++){
				System.out.print(yangHui[i][j] + "\t");
			}
			System.out.println();
		}
		
	}

}


相关资讯

发表评论
网友评论0 条评论)
暂无评论