|
public class yanghui
{
public static void main(String[] args)
{
int count=10;
int yanghui[][]=new int[count][0];
for(int i=0;i<=count;i++)
{
yanghui[i]=new int[i+1]; //这句出现错误;二维数据可以这样用是吗,不知道怎么改;
for(int j=0;j<=i;j++)
{
if (i==0)
yanghui[i][j]=1;
else
{
int value=0;
if(j>=1)
value+=yanghui[i-1][j-1];
if(j<i)
value+=yanghui[i-1][j];
yanghui[i][j]=value;
}
}
}
for(int i=0;i<count;i++)
{
for(int j=0;j<=i;j++)
System.out.println(yanghui[i][j]+"\t");
System.out.println();
}
}
}
求解答,我用的是eclipse |
|