0

I got everything until to the point that check if the space is emprty or not. I dont know how to do it. can someone give me an example?

2
Contributors
3
Replies
16
Views
2 Years
Discussion Span
Last Post by My_1
0
I was think something like this 
public static boolean checkforvaild (int number)
    {
        if (board[rows][cols] != " ")
        {
            return false;
        }
        else
        {
            return true;
        }
    }

but mine is in the switch withc conver from 1 to 9 into 2d array
0

Without knowing how your program and its data are structured, it's almost impossible to answer that question. What's the "switch" you refer to?
Anyway, converting an int 1-9 into row/col values is just simple arithmetic. You need the divide operator / and the remainder operator %

ps

        if (board[rows][cols] != " ")
        {
            return false;
        }
        else
        {
            return true;
        }

is a long way to say

return board[rows][cols] == " "

but also, note that != and == for Strings tests for being the same object; to test for twoo Strings having the same sequence of charatcters use String's equals method.

0
case 7: //check if the space is empty;
                    user = board [0][0] = 'X';
                    displayboard (board);
                    break;
            case 8: //check if the space is empty;
                    user = board [0][1] = 'X';
                    displayboard (board);
                    break;
            case 9: //check if the space is empty;
                    user = board [0][2] = 'X';
                    displayboard (board);
                    break;
            case 4: //check if the space is empty;
                    user = board [1][0] = 'X';
                    displayboard (board);
                    break;
            case 5: //check if the space is empty;
                    user = board [1][1] = 'X';
                    displayboard (board);
                    break;
            case 6: //check if the space is empty;
                    user = board [1][2] = 'X';
                    displayboard (board);
            break;
            case 1: //check if the space is empty;
                    user = board [2][0] = 'X';
                    displayboard (board);
                    break;
            case 2: //check if the space is empty;
                    user = board [2][1] = 'X';
                    displayboard (board);
                    break;
            case 3: //check if the space is empty;
                    user = board [2][2] = 'X';
                    displayboard (board);
                    break;
        }

I could not figure out how to pass it to other methor to check whether or not that space is empty for now

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.