Created
August 26, 2011 16:50
-
-
Save iainmcgin/1173840 to your computer and use it in GitHub Desktop.
Java Puzzle 2
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
import java.util.*; | |
import static java.util.Arrays.*; | |
import static java.lang.System.*; | |
class Main { | |
public static void main(String[] args) { | |
List<Integer> list = asList(1, 2, 3, 4, 5, 6); | |
Stack<Integer> filtered = new Stack<Integer>(); | |
Iterator<Integer> it = list.iterator(); | |
while(it.hasNext()) { | |
int val = it.next(); | |
if(val % 2 == 0) { | |
filtered.push(val); | |
} | |
} | |
while(!filtered.isEmpty()) out.println(filtered.pop()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment