该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package com.bift;
import java.io.*;
//杨辉三角
public class Test {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String input=br.readLine();
int n=Integer.parseInt(input);
int a[][]=new int[n][n];
for(int i=0;i
a[i][0]=1;
a[i][i]=1;//第一列和对角线都是1
}
for(int i=2;i
for(int j=1;j
a[i][j]=a[i-1][j]+a[i-1][j-1];
}
}
//打印
for(int i=0;i
for(int j=0;j<=i;j++){
String str="";
int value=a[i][j];
if(value<10){
str=value+" ";
}
if(value>=10 && value<100){
str=value+" ";
}
if(value>=100){
str=value+" ";
}
System.out.print(str);
}
System.out.println();//换行
}
}
}
最后
以上就是清爽大树最近收集整理的关于用java编写数字塔_求助,用循环方法输出以下数字塔的全部内容,更多相关用java编写数字塔_求助内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复