Skip to content

Instantly share code, notes, and snippets.

@nirodg
Created November 28, 2018 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nirodg/e544c28163c2fecb84ea4d46a1f7eeef to your computer and use it in GitHub Desktop.
Save nirodg/e544c28163c2fecb84ea4d46a1f7eeef to your computer and use it in GitHub Desktop.
Algorithm for checking if all values of an array are the same.
public static void main(String[] args) {
int[] age = new int[3];
age[0] = 16;
age[1] = 24;
age[2] = 30;
System.out.println(allValuesMatches(age));
}
private static boolean allValuesMatches(int[] values) {
for (int i = 0; i < values.length; i++) {
for (int e = 0; e < values.length; e++) {
if (values[i] != values[e]) {
return false;
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment