Im a beginner in JAVA and I have been trying to create a simple calculator program. I am facing a problem in the while loop where the loop does not wait for my input "ans" and directly jumps to the else clause
import java.util.Scanner;
public class scanner_program {
public static void main(String[] args)
{
Scanner ob = new Scanner(System.in);
int i = 1;
while (i==1)
{
System.out.print("Enter a number: ");
int num = ob.nextInt();
System.out.print("Enter another number: ");
int num2 = ob.nextInt();
System.out.println("Sum of "+num+" And "+num2+" is "+(num+num2));
System.out.println("Remainder of "+num+" And "+num2+" is "+(num-num2));
System.out.println("Product of "+num+" And "+num2+" is "+(num*num2));
float answer= (float) num/num2;
System.out.println("Quotient of "+num+" And "+num2+" is "+answer);
System.out.print("Try Again? (Y/N) ");
String ans = ob.nextLine();
if (ans=="Y" || ans=="y" ) {
// do nothing
}
else if (ans=="N" || ans=="n"){
break;
}
else {
System.out.println("Invalid input");
break;
}
}
}
}