public class YanghuiTriangleExample { 2 3 public static void main(String[] args) { 4 int rows = 10; 5 6 for(int i =0;i<rows;i++) { 7 int number = 1; 8 //打印空格字符串 9 System.out.format("%"+(rows-i)*2+"s",""); 10 for(int j=0;j<=i;j++) { 11 System.out.format("%4d",number); 12 number = number * (i - j) / (j + 1); 13 } 14 System.out.println(); 15 } 16 } 17 }
Java实现杨辉三角
猜你喜欢
转载自blog.csdn.net/pengjincheng1127/article/details/79848550
今日推荐
周排行