Considere a classe Main abaixo.
import java.util.*;
public class Main {
public static void main(String[] args) {
Stack<Integer> pp=new Stack<Integer>(); Stack<Integer> pi=new Stack<Integer>(); Stack<Integer> tc=new Stack<Integer>(); Scanner s=new Scanner(System.in); Integer var;
var=s.nextInt();
while( var > 0 ) {
tc.push(var);
var=s.nextInt();
} s.close();
while( !tc.empty() ) { var=tc.pop();
if( var%2 == 0 )
pp.push(var);
else pi.push(var);
}
while( !(pi.empty() || pp.empty()) ) { if( !pi.empty() )
System.out.printf("%d ", pi.pop()); if( !pp.empty() )
System.out.printf("%d ", pp.pop()); } } }
Suponha que a seguinte sequência de números inteiros tenha sido digitada por um usuário quando da execução do método main acima:

O que foi exibido no console pelo método main?