0

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));
}
}
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by pore
0

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

Edited by ~s.o.s~: n/a

0
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"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.