title: Can anyone help me with this? I am not getting the output
body: <p>In this program, I am trying get following output on case of operator correction, here, I want get output to check if a string is a valid arithmetic expression, then print valid &amp; if not(ex. a+, B+ or a+b+ or a b= c*d- and so on..) so I have designed this code in Java but, I am not getting output, when I tried for looping to check for checking the issue, but the value was not been changed outside the loop. Can anyone help me with this issue?</p>
  
  <p>Code:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class InvalidOperatorCheck {
  
    public static void main(String[] args){
      int i = 0;
      boolean flag = false;
  
      Scanner scan = new Scanner(System.in);
  
      System.out.println("Enter the Expression to test the string");
      String expression = scan.next();
  
      while (expression.isEmpty()) {
          if (i % 2 == 1) {
              if (expression.equals("+") || expression.equals("-") || expression.equals("/") || expression.equals("*"))
                  flag = false;
          }
  
          if (expression.length() - 1 == i) {
              if (expression.contentEquals("[a-zA-Z]"))
                  flag = true;
          } else {
              flag = false;
          }
  
          i++;
          i++;
      }
  
      if (flag == false) {
          System.out.println("\nNot Valid\n");
      } else {
          System.out.println("\nValid\n");
      }    
    }
  }
  </code></pre>