So I've been trying to make a simple calculator program in Java myself and I seem to have encountered a problem. The code doesn't seem to have an error (none showing in Eclipse or in Command Prompt), but when I run it it ends after you input the operation. Here's the example of my code:
public class vjezba1
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
Scanner text=new Scanner(System.in);
String opr;
int x;
int y;
int sum;
System.out.println("This is a simple calculator program.");
System.out.println("Input first number: ");
x = input.nextInt();
System.out.println("Input second number: ");
y = input.nextInt();
System.out.println("Choose an operation (+,-,*,/): ");
opr = text.nextLine();
if(opr == "+"){
sum = x + y;
System.out.println("Result is: " + sum);
}else if(opr == "-"){
sum = x - y;
System.out.println("Result is: " + sum);
}else if(opr == "*"){
sum = x * y;
System.out.println("Result is: " + sum);
}else if(opr == "/"){
sum = x / y;
System.out.println("Result is: " + sum);
}
}
}
Any and all insight is appreciated.