Java 尝试传递二维数组时出现不兼容类型错误

Java 尝试传递二维数组时出现不兼容类型错误,java,arrays,methods,compiler-errors,Java,Arrays,Methods,Compiler Errors,我试图将一个2d数组传递到另一个方法中,但它总是给我错误“int不能转换为int[][]”,返回行则相反。当我从Deal方法中删除[]时,它会给出一个错误,但反过来说“int[][]不能转换为int”。我做错了什么 //2-6 players face eachother in a game of Go Fish! import java.util.Scanner; import java.lang.String; import java.util.Random; //RNG public

我试图将一个2d数组传递到另一个方法中,但它总是给我错误“int不能转换为int[][]”,返回行则相反。当我从Deal方法中删除[]时,它会给出一个错误,但反过来说“int[][]不能转换为int”。我做错了什么

//2-6 players face eachother in a game of Go Fish!

import java.util.Scanner;
import java.lang.String;
import java.util.Random; //RNG

public class GoFish{
public static void main(String []args){
   Scanner in = new Scanner(System.in);
   System.out.println("This is a game simulation of Go Fish! It supports up to 6 players.");
   int Players = 0;
   System.out.println("How many players will be playing?");
   Players = in.nextInt();          //# of players
   while(Players < 2 || Players > 6){
      System.out.println("Please enter a number of players, between 2 and 6");
      Players = in.nextInt();
   }
   int [][] Cards = new int[Players + 1][54]; //Array for the cards. Final entry is the number of cards within the hand/deck, second to last number is the number of points.
   String [] Deck = new String [52];//This Array will contain the name for each card.
   Cards [0][52] = 52;              //Array 0 is the deck, Array 1 is the hand for player 1, Array 2 is the hand for player 2, ect.
   for(int i = 0; i < 52; i++){     //Fill the deck with cards.
      Cards [0][i] = 1;
   }
   int n = 5;                       //Number of cards to deal to the users.
   if(Players == 2)
      n = 7;                        //Increases to 7 if only 2 players are playing.
   for(int i = 0; i < n; i++){      //Deal cards for both players.
      for(int j = 0; j < Players; j++){
         Cards = Deal(Cards, Deck, Players);
      }
   }
}

static int Deal(int Cards[][], String Deck[], int Players){
return Cards;
}
}
//2-6名玩家在围捕游戏中面对面!
导入java.util.Scanner;
导入java.lang.String;
导入java.util.Random//RNG
公营狗鱼{
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(系统输入);
System.out.println(“这是一个模拟围棋的游戏!最多支持6名玩家。”);
整数=0;
System.out.println(“将有多少玩家参加比赛?”);
Players=in.nextInt();/#个玩家
而(玩家<2 | |玩家>6){
System.out.println(“请输入一些玩家,介于2和6之间”);
Players=in.nextInt();
}
int[][]Cards=new int[Players+1][54];//牌的数组。最后一个条目是手牌/牌组中的牌数,倒数第二个数字是点数。
String[]Deck=新字符串[52];//此数组将包含每张卡的名称。
牌[0][52]=52;//数组0为牌组,数组1为玩家1的牌,数组2为玩家2的牌,以此类推。
对于(inti=0;i<52;i++){//用卡片填充卡片组。
卡片[0][i]=1;
}
int n=5;//给用户发牌的数量。
如果(玩家==2)
n=7;//如果只有两个玩家在玩,则增加到7。
对于(int i=0;i
功能
Deal
返回int但您将卡定义为:int[][]卡。

什么是
Deal
应该做的?现在它什么都不做,将来它将修改牌组中的卡牌,以及正在抽牌的玩家的手,然后返回修改后的数组。将
Deal
的返回类型更改为
int[][]
,即
static int[][]交易(int-Cards[]],String-Deck[],int-Players){return-Cards;}
如何返回int?方法中的卡片定义为int Cards[];返回行上的错误表示“不兼容的类型:int[][]无法转换为int”。如果将返回行修改为“return Cards[][];”,则会出现.class错误。编辑:我看到了我的错误,我需要将[][]添加到函数本身,谢谢:)@Surav:是的,看到错误时非常混乱。我也很难在第一时间找到问题所在。