我正在尝试将我的字符数组 grid1 传递给名为 status 的方法。我收到错误 char 无法转换为 char[][]。我如何传递 grid1 以便它可以在 for 循环中工作?
for (int row = 0; row < 30; row++){
for (int col = 0; col < 30; col ++){
if (status(grid1[row][col], row, col)){
}
}
}
public boolean status(char [][] grid, int a, int b){
char value = grid[a][b];
if (value == 'X'){
//add X to another array
return true;
} else {
return false;
}
//add - to another array
}
最佳答案
问题是您的方法签名需要一个数组,并且您使用数组中的值来调用它。
调用方式如下:
status(grid1, row, col)
或修复方法签名
public boolean status(char grid){
char value = grid;
关于java - 将 CharArray 传递给方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21957125/