-2

I want to pass a int[][][] to a method points_of_game (and a int[][]) without first initialising the int[][][] as another variable.

My Code :

int[][] original_map = new int[9][9];
int[][] current_map = new int[9][9];
int[][] initial_map = new int[9][3];
.....
.....
.....
// INITIALISING THE int[][][] WITH THE VARIABLE return_maps WHICH I WANT TO AVOID.
int[][][] return_maps = {this.original_map, this.current_map};
points_of_game(return_maps, this.initial_map);

What I want:

int[][] original_map = new int[9][9];
int[][] current_map = new int[9][9];
int[][] initial_map = new int[9][3];
.....
.....
.....
// SOMETHING SIMILAR TO BELOW.
points_of_game({this.original_map, this.current_map}, this.initial_map);
Bohemian
  • 412,405
  • 93
  • 575
  • 722
aman
  • 307
  • 21
  • 48

1 Answers1

1

I think you want:

points_of_game(new int[][][]{this.original_map, this.current_map}, this.initial_map);

Or if you change you method signature to:

points_of_game(int[][] initial, int[][]... boards) {
    // boards has type int[][][]
}

You can call it like this:

points_of_game(this.initial_map, this.original_map, this.current_map);
Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Thanks. That was just the thing I was missing. Wasn't able to find it online – aman Oct 23 '18 at 22:39
  • *"Wasn't able to find it online"* - Have you tried a textbook? I am being serious here. Searching the web only works if you can express your "question" as something that matches the terminology that other people use. A text book ... well you can just read it cover to cover – Stephen C Oct 23 '18 at 22:49
  • Which textbook? – aman Oct 23 '18 at 22:50
  • Any textbook on Java programming. (Hint: try searching in Amazon.com, look for the popular ones, read the reviews, the ToCs, etc.) – Stephen C Oct 23 '18 at 22:51
  • okay I will try those – aman Oct 24 '18 at 00:15