Last active
December 13, 2015 18:18
-
-
Save riking/4953940 to your computer and use it in GitHub Desktop.
Java puzzler. From a Google Tech Talk.
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
import java.util.Set; | |
import java.util.HashSet; | |
public class ShortsPuzzle { | |
public static void main(String[] args) { | |
Set<Short> shortSet = new HashSet<Short>(); | |
for (short i = 0; i < 100; i++) | |
{ | |
shortSet.add(i); | |
shortSet.remove(i - 1); | |
} | |
System.out.println(shortSet.length()); | |
} | |
} | |
/* | |
What will this program output? | |
a) 0 | |
b) 1 | |
c) 100 | |
d) None of the above | |
"None of the above" could mean that it outputs something not in the answer | |
choices, throws an exception, or varies from run to run. | |
It does not include the possibility of the program failing to compile. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment