This question has already been answered:
- How to compare strings in java? 2 answers
I would like to contact you with a problem with my java calculator. Here is the code itself:
import java.util.Scanner; public class keken2{ public static void main(String arr[]){ Scanner input1 = new Scanner(System.in); Scanner input2 = new Scanner(System.in); Scanner input3 = new Scanner(System.in); int result = 0; System.out.println("enter first number:"); int num1 = input1.nextInt(); System.out.println("enter second number:"); int num2 = input2.nextInt(); System.out.println("enter operation(+, -, *, /):"); String oper = input3.next(); if(oper == "+"){ result = num1 + num2; System.out.println("result is:" + result); }else if(oper == "-"){ result = num1 - num2; System.out.println("result is:" + result); }else if(oper == "*"){ result = num1 * num2; System.out.println("result is:" + result); }else if(oper == "/"){ result = num1 / num2; System.out.println("result is:" + result); }else{ System.out.println("You have entered a wrong operator"); } } } But instead of the expected result, after entering all the data, only "You have entered a wrong operator" appears. Tell me please, what's the problem?