title: Variable 'number1' might not have been initialized
body: <p>I am getting this error <code>Error:(100,22) java:variable number1 might not have been initialized</code> and the same happens for <code>number2</code>. This is when I try to use the variable in an <code>if</code> statement.</p>
  
  <p>Where as, it says <code>Variable 'number1' is never assigned</code> and again the same for <code>number2</code> when I declared them.</p>
  
  <p>Setting the value to 0 will not help as in the last else if statement the statement will always be true.</p>
  
  <pre><code>public class event implements ActionListener {
      public void actionPerformed (ActionEvent a) {
          double number1, number2, add, substract, multiply, divide;
          String operator = a.getActionCommand();
  
          if (operator.equals("+")) {
              add = number1 + number2;
              result.setText(number1 + "+" + number2 + "=" + add);
              result.setForeground(Color.RED);
          }
          else if (operator.equals("-")) {
              substract = number1 - number2;
              result.setText(number1 + "-" + number2 + "=" + substract);
              result.setForeground(Color.RED);
          }
          else if (operator.equals("*")) {
              multiply = number1 * number2;
              result.setText(number1 + "*" + number2 + "=" + multiply);
              result.setForeground(Color.RED);
          }
          else if (operator.equals("/")) {
              if (number2 == 0) {
                  result.setText("Cannot divide by zero");
                  result.setForeground(Color.RED);
              }
              else {
                  divide = number1 / number2;
                  result.setText(number1 + "/" + number2 + "=" + divide);
                  result.setForeground(Color.RED);
              }
          }
      }
  }
  </code></pre>