I want my 2D array to actually output as a normal 5x5 grid rather than in a horizontal line or a vertical line, this is my code so far. (I'm using String for the numbers because I need to later replace them with "XX")
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class assignMain {
// Global declarations.
public static Scanner choice = new Scanner(System.in);
public static String player1 = "Player 1's card:";
public static String player2 = "Player 2's card:";
public static int i;
public static int j;
public static void main (String[] args) {
// Declare list to contain used numbers.
List<Scanner> usedNums = new ArrayList<>();
usedNums.add(choice);
// Declare card 1 numbers
String[][] card1 = { {"24", "2", "8", "1", "25"},
{"12", "16", "7", "17", "15"},
{"5", "6", "20", "19", "13" },
{"14", "23", "22", "4", "3" },
{"10", "18", "11", "21", "9"} };
// Declare card 2 numbers
String[][] card2 = { {"24", "21", "17", "15", "6"},
{"10", "3", "8", "18", "20" },
{"14", "7", "16", "12", "5" },
{"25", "23", "13", "19", "11"},
{"22", "4", "9", "1", "2" } };
printCard(card1, card2);
}
public static void printCard(String[][] card1, String[][] card2) {
System.out.println(player1);
for(i = 0; i < card1.length; i++) {
for(j = 0; j < card1.length; j++) {
System.out.println(card1[i][j]);
System.out.println();
}
}
}
}
The current output is :
Player 1's card:
24
2
8
1
25
12
16
7
17
15
5
6
20
19
13
14
23
22
4
3
10
18
11
21
9
What I'd like the output to be :
Player 1's card:
24 2 8 1 25
12 16 7 17 15
5 6 20 19 13
14 23 22 4 3
10 18 11 21 9
Basically want the grid to be symmetric and not all random, I intend to use \t if that's possible, if not then I'll be ok with other solutions which aren't too complicated. Please and thank you.