Question

What would cause my program to execute the first if statement no problem, but the second...

What would cause my program to execute the first if statement no problem, but the second it is throwing array out of index for some reason:

//Player 1 won on row 1
if (theBoard[0,0] == 1 && theBoard[0,1] ==1 && theBoard[0,2] ==1) {
return 1;
}
//Player 2 won on row 1
if (theBoard[0,0] == 0 && theBoard[0,1] ==0 && theBoard[0,2] ==0) {
return 1;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

It's throwing an Array out of index could be for the following reason:

1. The array is not initialized correctly.

2. Array size is nor defined properly as it should be at least arr[3][3] as per the statements above.

3. Array values are not defined for the index you are trying to access.

Please provide the complete program to check the other causes of the error.

Add a comment
Know the answer?
Add Answer to:
What would cause my program to execute the first if statement no problem, but the second...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What is the problem with my Program ? also I need a Jframe that desplays the...

    What is the problem with my Program ? also I need a Jframe that desplays the original input on the left side and the sorted input of the left side. my program is supose to read the number for basketball players, first name, last name, and float number that is less than 0 . on the left sideit is supposed to sort all this input based on last name. This is my demo class : package baseball; import java.io.*; import...

  • I am having trouble figuring out why my program will not make any columns, just rows....

    I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...

  • Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner...

    Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...

  • Write a simple polling program that allows users to rate 5 issues from 1 (low importance)...

    Write a simple polling program that allows users to rate 5 issues from 1 (low importance) to 10 (high importance). Use a one dimensional array of type String to store the five causes. Prompt for the number to be polled. Use a 5X(numPolled) int array to store the results of the survey, but please prompt for the file name. When you run the program ask a user rate each issue. The five issues are Environment, War and Peace, Economy, Education,...

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use...

    Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Displays the contents of the board array. Allows player 1 to select a location on the board for an X. The program should ask the user to enter...

  • Complete the program that solves the Eight Queens problem. The program’s output should look similar to:...

    Complete the program that solves the Eight Queens problem. The program’s output should look similar to: |1|0|0|0|0|0|0|0| |0|0|0|0|0|0|1|0| |0|0|0|0|1|0|0|0| |0|0|0|0|0|0|0|1| |0|1|0|0|0|0|0|0| |0|0|0|1|0|0|0|0| |0|0|0|0|0|1|0|0| |0|0|1|0|0|0|0|0| Use the Queens class given. In your implementation of the Queens class, complete the body of all methods marked as “To be implemented in Programming Problem 1.” Do not change any of the global variable declarations, constructor or placeQueens methods. Here is what I have so far with notes of what is needed. public class Queens...

  • 8.18 Ch 8, Part 3: Tabular Output Write this program using Eclipse. Comment and style the...

    8.18 Ch 8, Part 3: Tabular Output Write this program using Eclipse. Comment and style the code according to CS 200 Style Guide. Submit the source code files (.java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct. The program you are going to write will produce a String containing a tabular representation of a 2D String array. For the 2D arrays, assume that the first...

  • The first image is example of how I want answers and the second image is questions....

    The first image is example of how I want answers and the second image is questions. Can u please give me answers asap. Thank u. 7. hello_world.iml hello # C D Q , eaProjects hello_world - 7. hello_world.iml x Ant //Here is an example problem with answers so you can see what I am looking for. //For writing the recurrence relation, n is the length of the array - start 1/Precondition: start >= 0 public static int exampleProblem(int[] array, int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT