# Tag: arrays

## A zero-indexed array given & An equilibrium index of this array [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last month. Improve this question A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such

## 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

## Count total subsequences whose sum is divisible by k

I am trying to write a DP solution for the problem: count total number of sub-sequences possible of an array whose elements’ sum is divisible by k. I have written the following solution. But it is not giving the correct result. Like in the following code snippet, the array is {1, 2, 1} and k = 3. So expected total

## 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

## How do I convert [[Ljava.lang.String;@7defb4fb] to a String

I am trying to print the String, below is the code: Object[] objArr = data.get(key); for (Object obj : objArr) { System.out.println(obj); cell.setValue(obj); } but I get following output in …

## 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

## How to calculate a length of array with out using library

yesterday I appeared in interview,interviewer told me to write a code for calculating a length of array with out using a length property of Array class. For examaple- All answer given here are using String library. Answer

## How to add an item only if no other items exist with the same name in the arraylist?

How would I go about only inserting an item if the item does not have the same name as the other items in the arraylist within my insertUniqueItem() method? Answer You need to check if an item with the same name already exists in your list:

## 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