Ошибка несовместимых типов при попытке передать 2d массив - PullRequest
0 голосов
/ 08 ноября 2019

Я пытаюсь передать 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;
}
}

1 Ответ

0 голосов
/ 08 ноября 2019

Функция Deal возвращает int , но вы определили Карты как: int [] [] Карты.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...