//twoweishuzu.java
public class twoweishuzu
{ public static void main( String args[])
{ int a[4][5]={{1,1,2,4,6},
{3,7,6,5,4},
{5,6,5,4,3},
{56,34,56,78,21}};
int i,j;
for(i=0;i<4;i++)
{for(j=0;j<5;j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
}
public class twoweishuzu
{ public static void main( String args[])
{ int a[4][5]={{1,1,2,4,6},
{3,7,6,5,4},
{5,6,5,4,3},
{56,34,56,78,21}};
int i,j;
for(i=0;i<4;i++)
{for(j=0;j<5;j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
}
int a[][]={{1,1,2,4,6},
{3,7,6,5,4},
{5,6,5,4,3},
{56,34,56,78,21}};
你把 int a[4][5]= 改成int a[][]= 就好了,这是java和其他语言例如c不同的地方
{3,7,6,5,4},
{5,6,5,4,3},
{56,34,56,78,21}};
定义时直接初始化不用加数组的维数和长度!
public class twoweishuzu
{ public static void main( String args[])
{ int a[][]={{1,1,2,4,6},
{3,7,6,5,4},
{5,6,5,4,3},
{56,34,56,78,21}};
int i,j;
for(i=0;i <a.length();i++)//这里用数组长度比较清晰,并且方便以后的修改
{for(j=0;j <a[i].length();j++)//同上.
System.out.print(a[i][j] + " ");
System.out.println();
}
}
}