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:
4 16 8 12 7 14 9 15 -1
O que foi exibido no console pelo método main?
- A 7 4 9 16 15 8 12 14
- B 7 4 9 16 15 8
- C 15 14 9 12 7 8
- D 15 14 9 12 7 8 16 4
- E 4 7 16 9 8 15