java - Stack is not handling data properly -


ok, working on method splits numerical string characters , pushes each character sequentially integer 2 different stacks until sees operator skips , proceeds push rest of characters integers stacks. stack keeps displaying numbers not being read. text file being read looks this: 28302830-293817302

public void pushtostack(string line) {      boolean pushtofirststack = true;      (int = 0; < line.length(); i++) {          if (character.isdigit(line.charat(i))) {              if(pushtofirststack){                 system.out.print(character.getnumericvalue(line.charat(i)));                 stack1.push(character.getnumericvalue(line.charat(i)));             }else{                 system.out.print(character.getnumericvalue(line.charat(i)));                 stack2.push(character.getnumericvalue(line.charat(i)));             }              pushtofirststack = !pushtofirststack;         } else {             //sets operator             if(line.charat(i) == add){                 return;             }             else{                 setadd = false;             }         }     }     //displaying stacks debug     stack1.display();     stack2.display(); } 

the fact did not provide example output makes little hard answer, suspect line pushtofirststack = !pushtofirststack; should in else branch of if.

right now, building first stack digits odd indexes, , second digits indexes, resulting in interleaved output.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -