Skip to content

Tag: arrays

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: but I get following output in the console: I have tried the following snippets: But all of these are giving similar strange output: How do I get the string value out of it? ** Edit: ** My problem was to print and array of an array in Java. First

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 trying the below code there is an error on myarray5 and also when am printing the array: Answer There is a NullPoin…

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 exa…

Fastest way to sort an array of objects in java

I have a Class called apple which contains 3 values as int x, int y and int weight. Then i created an array of apple type objects. Now i want to sort the the array of objects based on weight meaning the the apple object with the lowest weight should be first and so on. I know there are quite