Skip to content

Instantly share code, notes, and snippets.

@iainmcgin
Created August 26, 2011 16:50
Show Gist options
  • Save iainmcgin/1173840 to your computer and use it in GitHub Desktop.
Save iainmcgin/1173840 to your computer and use it in GitHub Desktop.
Java Puzzle 2
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