title: Java Check for Calculator Program
body: <p>I'm fairly new to java coding and need help with a check for a calculator program I'm writing! This is what I'm trying to write a check for in my program: ---> if the user has entered an incorrect formula. Example: if they type “6 + 2 +” and don’t enter a number at the end, then press “=”, there should be an alert that they need to complete the formula correctly. How would I go about checking for this? I basically have the entire calculator going, but just kind of brain shot on what to do with this.</p>
  
  <pre class="lang-java prettyprint-override"><code>btnEqual.setOnAction(e -&gt;     
          {
  
              txtOutput.appendText(" = ");
              txtTickerOutput.appendText(" = ");
  
  
              String number = "";
  
              for(int i = 0; i &lt; numberStack.size(); i++)
              {
                  number += numberStack.get(i);
              }
  
              number = number.replaceAll("\\s+", ""); // get rid of whitespace 
  
              Integer intNumber = Integer.parseInt(number);
  
              intStack.push(intNumber);
  
  
              int num = 0;
  
              for(int i = 0; i &lt; numberStack.size(); i++)
              {
  
                  num = intStack.get(i);
  
  
                   for(int k = 0; k &lt;= operatorStack.size(); k++)
                  {
  
                      // try - catch 
                      try {
  
                      String str = operatorStack.get(k);
  
                      if(str.contains("+"))
                      {
                          num += intStack.get(++i); // pre-increment operators 
                      } 
  
  
                      else if (str.contains("-"))
                      {
                          num -= intStack.get(++i);
                      } 
  
  
                      else if (str.contains("/"))
                      {
                          num /= intStack.get(++i);
                      } 
  
  
                      else if (str.contains("*"))
                      {
                          num *= intStack.get(++i);
                      }
  
  
  
                      } catch (Exception x)
                          {
                              x.toString();
                          }
  
                  }
                }
  
  
                // print calculation to output 
                String calculation = String.valueOf(num);
  
                if (calculation.contains("=") == false)
                {
                    txtTickerOutput.appendText("Error: The formula does not contain an = sign!");
                }
  
                txtOutput.appendText(calculation);
                txtTickerOutput.appendText(calculation);
  
                // remove all elements from stacks 
                numberStack.removeAllElements();
                operatorStack.removeAllElements();
                intStack.removeAllElements();
  
  
          });
  
  </code></pre>