Analise o código Java abaixo. import java.util.*;public clas...
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 é