Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8793949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:11:16+00:00 2026-06-13T23:11:16+00:00

Hey im finishing up this tic tac toe project and i have one error

  • 0

Hey im finishing up this tic tac toe project and i have one error in my board class in my checkWin method where winner = board[0][i]; comes up as an incompatible error for Int and String. Ive fixed this on my other board line by using the Integer.toString() command but it won’t work for this. Any Ideas? Here’s the code for the checkWin method.

public boolean checkWin()
{
    {
        int i;  // i = column
        int j; // j = row
        int count; 
        int winner; 

          winner = empty; // nobody has won yet

// Check all rows to see if same player has occupied every square.

        for (j = 0; j < boardSize; j ++)
{
        count = 0;
    if (board[j][0] != Integer.toString(empty))

    for (i = 0; i < boardSize; i ++)
    if (board[j][0] == board[j][i])
    count ++;
    if (count == boardSize)
    winner = (board[j][0]);
}

// Check all columns to see if same player has occupied every square.

    for (i = 0; i < boardSize; i ++)
{
    count = 0;
    if (board[0][i] != Integer.toString(empty))
    for (j = 0; j < boardSize; j ++)
    if (board[0][i] == board[j][i])
    count ++;
    if (count == boardSize)
    winner = board[0][i];
}

// Check diagonal from top-left to bottom-right.

    count = 0;
    if (board[0][0] != Integer.toString(empty))
    for (j = 0; j < boardSize; j ++)
    if (board[0][0] == board[j][j])
    count ++;
if (count == boardSize)
winner = board[0][0];

// Check diagonal from top-right to bottom-left.

count = 0;
if (board[0][boardSize-1] != Integer.toString(empty))
for (j = 0; j < boardSize; j ++)
if (board[0][boardSize-1] == board[j][boardSize-j-1])
count ++;
if (count == boardSize)
winner = board[0][boardSize-1];

// Did we find a winner?

if (winner != empty)
{
if (winner == Xstr)

System.out.println("\nCongratulations! P1 You win!");
else if (winner == Ostr)

System.out.println("\nCongratulations! P2 You win!");
else


return true; 
}



}   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:11:17+00:00Added an answer on June 13, 2026 at 11:11 pm
    winner = board[0][i];
    

    winner is an int primitive type and board is multi-dimentional String Array.

    you are trying to assign a string for an int thus incompatible error for Int and String.

    String[][] board;  
    

    has Strings at its indexes, when you try to access board[0][i] you are retrieving a String.

    if your board array contains String representation of numbers like

          boards=  {{"1"},{"2"}};
    

    then use Integer.parseInt() which takes String as an argument and returns an Integer.

    winner = Integer.parseInt(board[0][i]);
    

    but mind you that if the String passed to parseInt is not a valid integer represetation of a string it’d throw NumberFormatException.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
hey guys having this really simple problem but cant seem to figure out have
Hey I have following code like this public object RetrieveItemRun(int item) { if (dictionary.ContainsKey(item))
Hey all i have two JFrames one is my main login frame, user enters
Hey I am getting this error: error: conversion to non-scalar type requested Here are
hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey all i am wondering why i am getting this error with the following
Hey i have been trying this for a while but with no luck. I
Hey I have made this GUI, that shows matplotlib plots in a tkinter interface
Hey i have been looking around and i cant find a way to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.