Questão de Programação — Linguagens de programação — UFES 2016
ProgramaçãoLinguagens de programação
- Código
- qq235473
- Banca
- UFES
- Órgão
- UFES
- Ano
- 2016
- Nível
- Superior
- Cargo
- Analista de Tecnologia da Informação
Analise o código Java abaixo.import java.util.*;public class TestMethod1{public static void main (String args []) {int total = 0;String str = "([(ola]))([([oi])] (eu estou))]";Stack<Character> s = new Stack<Character>();for(int count = 0; count < str.length(); count++){if ( str.charAt(count) == '(' || str.charAt(count) == '[')s.push( str.charAt(count) );else if ( str.charAt(count) == ')' )if ( !s.isEmpty() && s.peek() == '('){s.pop( );total++;} else {s.push( str.charAt(count) );}else if ( str.charAt(count) == ']' )if ( !s.isEmpty() && s.peek() == '['){s.pop( );total++;} else {s.push( str.charAt(count) );}}System.out.println ( total );}}A saída do código Java acima é
- A8
- B6
- C7
- D9
- E5