I have designed a matching game using a 2 dimensional int array (4x4). The coordinates on the array are populated with n numbers 1-8, each appearing twice. The numbers are then randomized. My problem is that I do not want the array to be populated with numbers, but rather letters a-h. However, I cannot seem to find a way to get this to happen without screwing up the int array i have made. Any suggestions? Source code...
I have added code tags, and you can see how much better the code looks . I also removed some unnecessary blank lines, because they don’t make the code easier to read.
Why have you only got one class? Why are all its members static?
You can probably copy all those numbers to another array. [By the way, there ain’t no such thing as a 2D array in Java. What you appear to have is an array of arrays, which does exist. It is different. Better than a 2D array.] As I said, copy all those numbers to another array, but in the meantime do some arithmetic with them. Did you know you can do arithmetic with chars? They are not letters, but numbers. So you can add 'a' to 1. Since 1 is an int, the result comes out as an int, so you have to cast it back. Because cast has a higher precedence than +, you need parentheses.
(char)('a' + i) Then you can put those chars into a new arrayOfArrays (char). Then you can find out how I have misled you slightly.