import java.io.*;
public class Yanghuisanjiao{
public static void main(String[] args) throws IOException{
int n;
String s;
BufferedReader bu;
try{
System.out.print("请输入行数:");
bu=new BufferedReader(new InputStreamReader(System.in));
s=bu.readLine();
}
catch(IOException e){
System.out.println("不是数字型");
return;
}
try{
n=Integer.parseInt(s);
}
catch(NumberFormatException p){
System.out.println("输入的为非数值");
return;
}
if(n<0)
throw new IOException("输入值不能为负数!");
int yhsj[][]=new int[n][n];
for(int i=0;i
yhsj[i][0]=1;
if(i==j){
yhsj[i][j]=1;
}
if(i>1&&j>0)
yhsj[i][j]=yhsj[i-1][j]+yhsj[i-1][j-1];
}
}
System.out.println("杨辉三角为:");
for(int i=0;i
System.out.print(yhsj[i][j]+" ");
System.out.println();
}
}
}
你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=1941608