Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Stack<String> pila = new Stack<String>();
- int c1=0;
- int c2=0;
- int c3=0;
- String xp = "{(a+b)+(c-d)*6/8} + {[r*3]+[d*r]}";
- System.out.println(xp);
- for (int x = 0; x < xp.length(); x++) {
- String a1 = String.valueOf(xp.charAt(x));
- pila.push(a1);
- if (!(a1 == "}") || !(a1 == "]") || !(a1 == ")") || !(a1 == "{") || !(a1 == "[") || !(a1 == "(")) {
- pila.pop();
- System.out.println(pila);
- } else {
- for (int x1 = 0; x1 < pila.size(); x1++) {
- if (pila.get(x1) == "{") {
- c1++;
- if (!(pila.search("}")==-1)) {
- c1=c1-1;
- }
- } else if(pila.get(x1) == "[") {
- c2++;
- if (!(pila.search("]")==-1)) {
- c2=c2-1;
- }
- } else if(pila.get(x1) == "(") {
- c3++;
- if (!(pila.search(")")==-1)) {
- c3=c3-1;
- }
- }
- }
- }
- }
- if (c1==0 || c2==0 || c3==0) {
- System.out.println("La ecuacion esta balanciada");
- } else {
- System.out.println("La no ecuacion esta balanciada");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement