【发布时间】:2018-05-29 17:27:28
【问题描述】:
我写了这段代码。出于某种原因,我得到了新矩阵,但原始矩阵的最后一个值似乎丢失了......
public static char[][] Frame_of_zeros(char[][]a)//builds an external frame of zeroes
{
char[][]c3=new char[a.length+1][a[0].length+1];
for(int i=0,j=0;i<c3.length;i++)//left column is composed of zeroes
{
c3[i][j]='0';
}
for(int j=0,i=0;j<c3[0].length;j++)//upper row of zeroes
{
c3[i][j]='0';
}
for(int i=c3.length-1,j=0;j<c3[0].length;j++)//most lower row composed of zeroes
{
c3[i][j]='0';
}
for(int i=0,j=c3[0].length-1;i<c3.length;i++)//right column is composed of zeroes
{
c3[i][j]='0';
}
for(int i=1,k=0;i<c3.length-1&&k<a.length;i++,k++)//i for the modified and k is the original
{
for(int j=1,l=0;j<c3[0].length&&l<a[0].length-1;j++,l++)//j for the modified and l is the original
{
c3[i][j]=a[k][l];
}
}
return c3;
}
【问题讨论】:
-
您需要清楚详细地解释您预期会发生什么以及实际会发生什么。 IE。举一个具体的例子。请访问help center 并阅读How to Ask。
标签: java arrays multidimensional-array