Ask Experts Questions for FREE Help !
Ask
    marke123's Avatar
    marke123 Posts: 1, Reputation: 1
    New Member
     
    #1

    Mar 14, 2015, 09:50 PM
    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

Check out some similar questions!

Uncertainty on Operator [ 0 Answers ]

http://www.texify.com/img/\normalsize\!\langle\hat A\rangle.gif is the expectation value of http://www.texify.com/img/\normalsize\!\langle\hat A\rangle.gif I don't know what means expectation value of an opertor, square of an operator and square of all items texify.com/img/\LARGE\!\langle\hat...

Write a program to Overload the addition operator (+) to add two Polynomials. [ 1 Answers ]

Develop class Polynomial. The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent. The term 2x4 has a coefficient of 2 and an exponent of 4. Develop a full class containing proper constructor and destructor functions as well as set and get...

Write a program to Overload the addition operator (+) to add two Polynomials. [ 0 Answers ]

Develop class Polynomial. The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent. The term 2x4 has a coefficient of 2 and an exponent of 4. Develop a full class containing proper constructor and destructor functions as well as set and get...

Operator's Manual [ 2 Answers ]

I have a Montgomery Ward 12/38 Industrial Commercial riding mower. I despartely need an "owners Manual" Can you help me?


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.