【发布时间】:2015-09-16 14:40:28
【问题描述】:
觉得昨天被问到同样的问题很愚蠢,但今天在不同的情况下可以做同样的事情。
single[z][i] = (board[i].split("?!^"));
这行给了我一个错误:需要不兼容的类型:字符串 找到:字符串[] 1 个错误 我知道它是因为它是一个 2D 数组和拆分给它自己的字符串输出,但不知道如何修复。 这是我所有的代码:
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int player;
String board[] = new String[8];
String single [] [] = new String [8] [8];
//single[0][0] = "hi";
//If player is 1, I'm the first player.
//If player is 2, I'm the second player.
player = in.nextInt();
//Read the board now. The board is a 8x8 array filled with 1 or 0.
for(int i = 0; i < 8; i++) {
if(in.hasNext()){
board[i]= in.next();
}
}
for(int z = 0; z < 8; z++){
for(int i = 0; i < 8; i++) {
single[z][i] = (board[i].split("?!^"));
}
}for(int z = 0; z < 7; z++)
for(int i = 0; i < 7; i++) {
if((single[z][i].equals(1)) && (single[z][i+1].equals(1)) &&(single[z+1][i].equals(1))){
System.out.print(z + ""+ i);
}
}
nextMove(player,board);
}
}
【问题讨论】:
-
你甚至没有解释你的代码的意图。我们可以通过阅读来猜测,但这很无聊。您必须使您的问题易于阅读。
-
抱歉,我正在尝试确定网格上 1 的坐标,用于游戏
-
String.split()返回一个String[];您正在尝试将其分配给String。
标签: java multidimensional-array incomplete-type