The homework question I'm working on is asking me to return true if all the elements in a list have the same value, or false if any of the elements have different values. I wrote the following code to accomplish this:
public static boolean allSame (double[] list) {
double sameReference = list[0];
for (int i = 1; i < list.length; i++) {
if (list [i+1] = sameReference)
continue;
else return false;
return true;
}
}
It seems to work well, except I'm running into a single error in line 3: Type mismatch: cannot convert from double to boolean
Could someone explain what is being converted from a double too Boolean, and what I wrote that is converting it? How would I go about resolving this error? Thank you for the help!
Aucun commentaire:
Enregistrer un commentaire