Created
November 28, 2018 13:11
-
-
Save nirodg/e544c28163c2fecb84ea4d46a1f7eeef to your computer and use it in GitHub Desktop.
Algorithm for checking if all values of an array are the same.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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