Cadernos de Questões

Provas Favoritas

Filtros Salvos

Foram encontradas 50 questões.
#2255801

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 é 

  • 8
  • 6
  • 7
  • 9
  • 5
Fale com IAgo
IAgo - Assistente IAProva
IA
Olá! Sou o IAgo, seu assistente aqui no IAProvatec 😊
Veja como posso te ajudar:
Agora