我弄清楚为什么只有一半的列打印出来。包含所有字符的文件之间有空格。打印方法也在白色空间中读取。
Ex: a b c d
e f g h
有一些String方法可以修剪和删除,但我不能将它与char一起使用。有谁知道我可以用来删除空格?
public void print()
{
for(int i = rows; i < board.length; i++)
{
for(int j = columns; j < board[0].length; j++)
{
System.out.print( board[i][j] );
}
System.out.println();
}
}
}
答案 0 :(得分:0)
我觉得这个方法错了
public void print()
{
for(int i = rows; i < board.length; i++)
{
for(int j = columns; j < board[0].length; j++)
{
System.out.print( board[i][j] );
}
System.out.println();
}
}
如果循环从0开始, for(int i = rows; i < board.length; i++)
看起来很可疑吗?
答案 1 :(得分:0)
您在打印方法中使用了board [0]而不是board [i]。
for(int j = columns; j < board[i].length; j++)
{
System.out.print( board[i][j] );
}
System.out.println();
}
答案 2 :(得分:0)
我相信这是你的问题。 您在for循环中的代码:
for(int i = rows; i ...
从行和列开始。它应该从0开始,然后转到行和列,如下所示:
for(int i = 0; i&lt; rows ...
其他帖子告诉你问题是你要登上[0] .length而不是board [i] .length,因为你正在使用一个长度和一个高度的网格,所以不能正确。这不会从电路板[0]。长度变为电路板[1]。长度等。