Hello, thanks for taking the time to read this.
I'm working on (what should be) a simple, simple java program, I am very new to java so please bear with me.
I'm writing code with a method that takes an array of int values and determines if all the numbers are different from each other, that they are distinct.
Here is what I have so far:
public class Array
{
public static void main(String[] args)
{
int[] numbers = {5, 10, 15, 20, 25, 1, 2};
System.out.println("Checking array to determine if all numbers are different: " +
compareValues(numbers));
}
public static boolean compareValues(int[] numArray)
{
for(int i = 0; i < numArray.length; i++)
{
for(int j = 0; j < numArray.length; j++)
{
if((numArray[i] == (numArray[j])) && (i != j))
{
return true;
}
}
}
return false;
}
}
My code compiles, but the result I get is false... when it should be true (because all the values ARE distinct). I feel like its all wrong!
@compareValues, here is where I am stuck. I am having much difficulty in creating for-loops. Am I using 1 to many for-loops? Should I be using for-loops?
If anyone could help and explain their reasons it would be very much appreciated!