我有一个数组:
public String[][] bombBoard = new String[9][9];
这个数组填充了值 (*),但随机还有一些其他值 (@)。
稍后在程序中我想告诉用户(@)在哪里,如果附近有:
public void loadNumbers()
{
try
{
if (bombBoard[bombRow][bombCol] == "@")
{
System.out.println("You have landed on a bomb!");
//break
}
else if (bombBoard[bombRow+1][bombCol].equals("@"))
{
System.out.println("There is a bomb in the vicinity!" + bombBoard[bombRow+1][bombCol]);
}
else if (bombBoard[bombRow-1][bombCol] == "@")
{
System.out.println("There is a bomb in the vicinity!" + bombBoard[bombRow-1][bombCol]);
}
else if (bombBoard[bombRow][bombCol+1] == "@")
{
System.out.println("There is a bomb in the vicinity!" + bombBoard[bombRow][bombCol+1]);
}
MORE CODE...
}
}
它打印:"There is a bomb in the vicinity!@"
我要打印"There is a bomb at 3, 2"
可能很简单,但我正在画空白。而不是拉回元素内部的内容,我想要元素索引(我想)。请停下来!