Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   My operator program (https://www.askmehelpdesk.com/showthread.php?t=809328)

  • Mar 14, 2015, 09:50 PM
    marke123
    My operator program
    import java.util.*;
    class calc12345
    {
    public static void main()
    {
    int a,b,c;


    String a1;
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter first number");
    a=sc.nextInt();
    System.out.println("Enter second number");
    b=sc.nextInt();
    System.out.println("Enter the operator");
    a1=sc.next();
    if(a1=="+")
    System.out.println(a+b);
    else if(a1=="-")
    System.out.println(a-b);
    else if(a1=="/")
    System.out.println(a/b);
    else if(a1=="*")
    System.out.println(a*b);
    else if(a1=="%")
    System.out.println(a%b);
    else
    System.out.println("Invalid Operator");
    }
    }
    I have entered the operator "+" & it is saying invalid operator

  • All times are GMT -7. The time now is 07:26 AM.