title: How to make an efficient expression calculator?
body: <p>How to make the code read multiple operands in the expression entered by the user.</p>
  
  <p>If i have to read them how to find the different operators and operands here is the code for basic expression calculator made by me which is able to read the expression and evaluate only one operand and two operators </p>
  
  <p><b>e.g.</b>
  If input is 2+3
  it will give me 5.0 as result
  <br>
  <b> but</b>
  if input is 2 + 3, i.e with space it gives no output at all how to make it work correctly even in case of a space.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Calc {
  
  public static void main(String args[]){
  
      int j=0;
  
      float op1=0,op2=0,result=0;
  
      Scanner inp=new Scanner(System.in);
  
       System.out.println("Sir,Please enter the expression");
  
       String exp1=inp.next();
  
       String exp = exp1.replaceAll(" ","");
  
        for(int i=0;i&lt;exp.length();i++){
  
           if(exp.charAt(i)=='+'||exp.charAt(i)=='-'||exp.charAt(i)=='*'||exp.charAt(i)=='/'){
  
             if(exp.charAt(i)=='+'){
  
                     i=j;
  
                     op1=Float.parseFloat(exp.substring(0, j+1));
  
                     op2=Float.parseFloat(exp.substring(j+2,exp.length()));
  
                     result=op1+op2;
  
                     System.out.println(result);
  
                     break;
               }
  
               if(exp.charAt(i)=='*'){
  
                     i=j;
  
                     op1=Float.parseFloat(exp.substring(0, j+1));
  
                     op2=Float.parseFloat(exp.substring(j+2,exp.length()));
  
                     result=op1*op2;
  
                     System.out.println(result);
  
                     break;
  
               }
  
               if(exp.charAt(i)=='-'){
  
                     i=j;
  
                     op1=Float.parseFloat(exp.substring(0, j+1));
  
                     op2=Float.parseFloat(exp.substring(j+2,exp.length()));
  
                     result=op1-op2;
  
                     System.out.println(result);
  
                     break;
               }
  
               if(exp.charAt(i)=='/'){
  
                     i=j;
  
                     op1=Float.parseFloat(exp.substring(0, j+1));
  
                     op2=Float.parseFloat(exp.substring(j+2,exp.length()));
  
                     if(op2==0){
  
                         System.err.println("Division by zero is not possible");
  
                         break;
  
                     }
  
                     else{
  
                        result=op1/op2;
  
                        System.out.println(result);
  
                        break; 
                     }
  
               }
           }
  
  
       }
  
  }
  
  }
  </code></pre>