0

EDIT EDIT EDIT Okay, I've boiled down the for loop, but now I've got a problem with the cell assignment it seems.

 int itemsX = (int) n*n*(percentX/100);
    int itemsBlank = (int) n*n*(percentBlank/100);
    int itemsO = (n*n) - (itemsBlank + itemsX);
    // Now we construct the grid.
    for (i = 0; i < n; i++) { 
        for ( j = 0; j< n;  j++) {
            double q  = Math.random();
            // In this first set of If/Else's, the program will 
            // use a random number generator to place our items. 
            if (q >= .66 && a < itemsBlank) {
                tissue[i][j] = ' ';
                a = a + 1;
            // In the event the Program has used up all of one particular item in a grid before finishing,
            //it will redirect the randomized value to a different item to be put in place.
            }if (q >= .66 && a == itemsBlank){
                    q = q - .33; }
             if (q < .66 && q >= .33 && b < itemsO) {

                tissue[i][j] = 'O';
                b = b + 1;
            if (q <.66 && q >= .33 &&  b == itemsO)
            { q = q - .33;
            }if (q < .33 && c < itemsX) {
                tissue[i][j] = 'X';
                c = c + 1;
            }if (q < .33 && c == itemsX)
             {q = q + .66;
             }
            if(q >= .66 && a < itemsBlank) {
                tissue[i][j] = ' ';
                a = a + 1;
             } 
            System.out.print(tissue[i][j]);
            }
        }System.out.println(); 
    }
}

Also, I deleted the excess text because I imagine the wall of text was unbearable to look at.

EDIT EDIT Scratch that, I think I understand what might be the problem. I won't be able to use the simple way to print the array as I'm barred from using the java.util.scanner library, so I'll have to print it manually. So I think my problem is I'll need to simply work out designing a double for loop for this. I'll see if I can do it myself, but any additional input would be greatly appreciated.

EDIT: Special thanks to rgettman for helping me understand how to print the array.

Akkere
  • 5
  • 2
  • possible duplicate of [What's the simplest way to print an array?](http://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-an-array) – ajb Nov 24 '14 at 23:39

1 Answers1

1

Arrays are objects too, but they don't override Object's toString() method, which is responsible for the output [[C@36d98810.

In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())

Because it's a multi-dimensional array, you should call Arrays.deepToString to output the contents of the entire array.

System.out.println(Arrays.deepToString(tissue));
Community
  • 1
  • 1
rgettman
  • 176,041
  • 30
  • 275
  • 357
  • I completely forgot about that strange quirk. I've adjusted the print output and now it simply prints blank cells "[[ , , , , , ], [ , , , , , ]", so it looks like the only other problem left to solve for this part is in the cell algorithm. Thank you very much for helping me get this far! – Akkere Nov 24 '14 at 23:52