Originally Posted by
jean28
... but for some reason...
So, what if the array contains [1.0, 3.0, 0.0]? What would you expect? What does it give?
What if the array contains [1.0, 2.0, 3.0, 2.0, 5.0, 6.0]? What would you expect? What does it give?
Well, I'll create a couple of arrays and print out each array and result from your method...
import java.util.*;
public class FloatingArray {
public static void main(String [] args) {
float [] x = {1, 3, 0};
System.out.println("x = " + Arrays.toString(x));
System.out.println("FloatingArray.isDifferent(x) = " + FloatingArray.isDifferent(x));
System.out.println();
float [] y = {1, 2, 3, 2, 5, 6};
System.out.println("y = " + Arrays.toString(y));
System.out.println("FloatingArray.isDifferent(y) = " + FloatingArray.isDifferent(y));
} // End of main
public static boolean isDifferent(float [] array) {
.
.
.
Output
x = [1.0, 3.0, 0.0]
FloatingArray.isDifferent(x) = true
y = [1.0, 2.0, 3.0, 2.0, 5.0, 6.0]
FloatingArray.isDifferent(y) = false
Are the outputs for these examples correct? (I think they are.)
Bottom line:
How about showing us an example for which you think it gives an incorrect result? Maybe someone can walk you through it...
Cheers!
Z