首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

帮忙看下这个程序的有关问题

2013-07-04 
帮忙看下这个程序的问题我是个菜鸟,今天写杨辉三角,这是程序:class Yanghui{public static void sanjiao(i

帮忙看下这个程序的问题
我是个菜鸟,今天写杨辉三角,这是程序:
class Yanghui
{
public static void sanjiao(int n)
{
int[][] arr=new int[n][];
for(int x=0;x<n;x++)
{

for(int z=x+1;z<n;z++)
{
System.out.print(" ");
}
for(int y=0;y<=x;y++)
{


if(y==0||x==y)
 arr[x][y]=1;
else
{
if(x!=n-1)
arr[x+1][y+1]=arr[x][y]+arr[x][y+1];
}

System.out.print(arr[x][y]);
}
System.out.println("  ");
}
}
}
public class Test2
{
public static void main(String[] args)
{
Yanghui.sanjiao(8);
}
}
编译能够通过,但是运行老是提示什么好像是主函数没有指向的异常的英文,求大侠指点,是不是程序毛病特别多。我的环境变量设置也是没问题的。谢谢。
[解决办法]
int[][] arr=new int[n][];
你的第二维没有定义长度。。。

int[][] arr=new int[n][n];
或者类似
arr[i] = new int[n];

热点排行
Bad Request.