java—我得到了这个错误消息并理解了原因:不能应用于给定的类型;必需:未找到扩充:int,int

sauutmhj  于 2021-07-03  发布在  Java
关注(0)|答案(2)|浏览(309)

这可能是睡眠不足的情况,但我不明白为什么我得到这个信息,我知道这将是一个简单的解决办法,但我不能把我的头围绕它,任何帮助是感激的。
对于context,我尝试获取用户的输入,然后将其插入,并将其与2d数组中的值进行比较。
这就是我要比较的数组

  1. String[][] board = {{"-", "-", "-", "-", "-", "-", "-", "-"},
  2. {"-", "-", "-", "-", "-", "-", "-", "-"},{"-", "-", "-", "-", "-", "-", "-", "-"},
  3. {"-", "-", "-", "-", "-", "-", "-", "-"},{"-", "-", "-", "-", "-", "-", "-", "-"},
  4. {"-", "-", "-", "-", "-", "-", "-", "-"},{"-", "-", "-", "-", "-", "-", "-", "-"},
  5. {"-", "-", "-", "-", "-", "-", "-", "-"}};
  1. public void makeMove(){
  2. Scanner choice = new Scanner(System.in);
  3. System.out.println("Enter the row");
  4. int tempCol = choice.nextInt();
  5. System.out.println("Now the column");
  6. int tempRow = choice.nextInt();
  7. //a.setPiece(tempRow, tempCol, "W");
  8. a.isValid(tempRow, tempCol);
  9. }

a、 isvalid正在抛出错误消息:

  1. method isValid in class board cannot be applied to given types;
  2. required: no arguments
  3. found: int, int
  4. reason: actual and formal argument lists differ in length

这就是我试图与之沟通的方法:

  1. public void isValid(){
  2. if(board[tempRow][tempCol] = "W"){
  3. display();
  4. } else {
  5. System.out.println("Move invalid, try again");
  6. makeMove();
  7. }
  8. }

这也抛出了一个不同的错误消息,但我将创建一个新的问题

mqkwyuun

mqkwyuun1#

isvalid()没有声明任何参数,但您正在传递两个int。你想这样申报吗?

  1. public void isValid(int tempRow, int tempCol){
  2. if(board[tempRow][tempCol] = "W"){
  3. display();
  4. } else {
  5. System.out.println("Move invalid, try again");
  6. makeMove();
  7. }
  8. }
zujrkrfu

zujrkrfu2#

你的 isValid 方法不接受任何参数,但您尝试将其传递给2 int 不管怎么说,这是我的错。你得把你的声明改成:

  1. public void isValid(int tempRow, int tempCol){

这样你就可以 int 并处理它们。

相关问题