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?

Recommended Answers

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 …
Jump to Post

All 3 Replies

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.