Hello,
I'm working at a 8 puzzle (http://www.permadi.com/java/puzzle8/)
i want to compare two arrays.
after that I want to get a true or a false and then I want to implement a algorithm.
my question is:
why can I not use 2 different variables and display the interger values of each array?
how can I continue work with the return value false/true from Arrays.equals(initialstate, goalstate).

Thanks a lot

import java.util.Arrays;

public class Input {

public static void main(String[] args) {
int[] initialstate = new int[] { 1, 2, 3, 4, 8, 0, 7, 6, 5 };
int[] goalstate = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
System.out.println(i + "initialelement:" + initialstate[i]);
System.out.println(j + "goalelement:" + goalstate[j]);
System.out.println(Arrays.equals(initialstate, goalstate));
}
}

Recommended Answers

All 2 Replies

> why can I not use 2 different variables and display the interger values
> of each array? System.out.println(Arrays.toString(myIntArray)); .

> how can I continue work with the return value false/true from
> Arrays.equals(initialstate, goalstate).

Sorry but this isn't clear. What exactly do you mean by 'how can I continue'? Post the code which are trying to run along with what is expected and what you are getting.

public class Input {

	public static void main(String[] args) {
		
		int[] initialstate = new int[] { 1, 2, 3, 4, 8, 0, 7, 6, 5 };
		int[] goalstate = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
System.out.println(Arrays.toString(goalstate));
System.out.println(Arrays.toString(initialstate));
		System.out.println(Arrays.equals(initialstate, goalstate));
if (Arrays.equals(initialstate, goalstate))
		{System.out.println("algorithm is ready");
		}
else System.out.println("algorithm needs to continue");
	}
}

Thanks for help.
I got the if statement.
that was meant by the "how to continue"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.