Last active
April 20, 2018 13:28
-
-
Save entrofi/63d96ac4197046132912bc9f9d27e0d2 to your computer and use it in GitHub Desktop.
Java Puzzlers Un welcome guest
This file contains hidden or 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 class Loop { | |
public static void main(String[] args) { | |
int[][] tests = {{6, 5, 4, 3, 2, 1}, {1, 2}, | |
{1, 2, 3}, {1, 2, 3, 4}, {1}}; | |
int successCount = 0; | |
try { | |
int i = 0; | |
while (true) { | |
if (thirdElementIsThree(tests[i++])) | |
successCount++; | |
} | |
} catch (ArrayIndexOutOfBoundsException e) { | |
// No more tests to process | |
} | |
System.out.println(successCount); | |
} | |
private static boolean thirdElementIsThree(int[] a) { | |
return a.length >= 3 & a[2] == 3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment