Я написал этот код. По какой-то причине я получаю новую матрицу, но кажется, что последнее значение исходной матрицы отсутствует ...
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;
}
Вам необходимо подробно объяснить, что произойдет с ожидать и что произойдет с фактически. Т.е. покажите конкретный пример. Посетите центр помощи и прочтите Как спросить.




Внешний фрейм означает, что вам нужно добавить по две строки / столбца (левый и правый / верхний и нижний), поэтому вам нужно увеличить размер вашей новой матрицы на дополнительную строку и столбец. Циклы для установки кадра на 0 были в порядке. В последнем внутреннем цикле вы устанавливаете уменьшенный размер исходной матрицы как условие вместо нового, как во внешнем цикле.
public static char[][] Frame_of_zeros(char[][]a)//builds an external frame of zeroes
{
char[][]c3=new char[a.length+2][a[0].length+2];
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-1 && l<a[0].length;j++,l++)//j for the modified and l is the original
{
c3[i][j]=a[k][l];
}
}
return c3;
}