Skip to content
Advertisement

Tag: arrays

Getting only the first name in an array

I have an array list like this: ArrayList names = new ArrayList<>(); that stores people’s first and last names when they are entered in different textbooks. So when prompted to Joe Biden would be element number 1 then Barack Obama would be element number 2 in the array list. My question is that if it is possible to only get

Connect 4 check for a win algorithm

I know there is a lot of of questions regarding connect 4 check for a win. The issue is that most of other algorithms make my program have runtime errors, because they try to access an index outside of my array. My algorithm is like this: count is the variable that checks for a win if count is equal or

Declare an array in java without size

Hello am trying to declare an array in java but i do not want the array to have a specific size because each time the size must be different. I used this declaration: int[] myarray5; but when am …

Referencing from an inner class

I have the following code My aim here is to create an array of JTextFields which have a keylistener on. This keylistener should prevent anything other than numbers being entered in the JTextField. It should also change the color of the JTextField’s background if the number entered is not an int. For example 2147483647554. However when I compile this I

In the knights tour challenge, from the coordinates the player is currently on to show the user where they can move

This is from my attempt at the knights tour game, and what I was trying to do here was show the user what moves they could make from whatever position they are in, in the array. The problem arrives with NextPos[x+1][y-2]!=null in the if statement, as the exception java.lang.ArrayIndexOutOfBoundsException: -2 is thrown. I know the array is out of bounds

Advertisement