Note that there are some explanatory texts on larger screens.

plurals
  1. POreading char array of number more than 10
    primarykey
    data
    text
    <p>i am not sure how can i read a number like 10 and above for a char array, i am converting from infix to postfix , currently i am able to do so for single digits however when it comes to multiple digits when evaluating the postfix equation it would be a wrong answer. for example 10+13+4 it would give a wrong answer but 1+3+4 it would be correct.</p> <pre><code> //class main calcParser calc = new calcParser("13+20+3+4"); calc.toPostfix(); calc.displayPostfix(); calc.evaluatePostfix(); calc.displayResult(); // result for above would be 1320+3+4+ 9.0 // class calcParser public void toPostfix() { for(char c : originalExp.toCharArray()) { switch(c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': postfixExp.append(c); break; case '+': case '-': if(postfixStack.empty()) { postfixStack.push(c); } else { if((postfixStack.peek().equals(c))) { postfixExp.append(postfixStack.pop()); postfixStack.push(c); } else { postfixExp.append(postfixStack.pop()); postfixStack.push(c); } } break; } } while(!postfixStack.empty()) { postfixExp.append(postfixStack.pop()); } } public void evaluatePostfix() { String postfix = postfixExp.toString(); for(char c : postfix.toCharArray()) { switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': postfixResultStack.push(c); break; case '+': firstOperand = Double.parseDouble(postfixResultStack.pop().toString()); secondOperand = Double.parseDouble(postfixResultStack.pop().toString()); postfixResultStack.push(firstOperand + secondOperand); break; case '-': firstOperand = Double.parseDouble(postfixResultStack.pop().toString()); secondOperand = Double.parseDouble(postfixResultStack.pop().toString()); postfixResultStack.push(firstOperand - secondOperand); break; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload