I want to ask user to insert operator and get the answer till user enters keys other than +,-,* or \ .I did the program like this.But it will not work properly.Its looping even for other keys.What is the problem with the coding?
public static void main(String Args[]) throws IOException
{
InputStreamReader myrdr=new InputStreamReader(System.in);
BufferedReader myBfr=new BufferedReader(myrdr);
Scanner myScanner=new Scanner(System.in);
String mathOp;
float Res,Num1,Num2;
System.out.print("Mathematical Operator :");
mathOp=myBfr.readLine();
Res=0;
while(mathOp!="+"||mathOp!="-"||mathOp!="*"||mathOp!="\\")
{
System.out.print("Enter number one: ");
Num1=myScanner.nextInt();
System.out.print("Enter Number Two: ");
Num2=myScanner.nextInt();
switch(mathOp)
{
case "+":
Res=Num1+Num2;
break;
case "-":
Res=Num1-Num2;
break;
case "\\":
Res=Num1/Num2;
break;
case "*":
Res=Num1*Num2;
break;
default:
{
System.out.println("Programme Exits");
return;
}
}
System.out.println("Answer is : "+Res);
System.out.print("Mathematical Operator :");
mathOp=myBfr.readLine();
}
}