Basic Calculator: Compilation error, not sure where it came from

public class BasicCalculator {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		char ch = sc.next().charAt(0);
		int res;
		do{
			if(ch == 'X' || ch == 'x'){
				break;
			}
			else if(ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '%')
			{
				int n1 = sc.nextInt();
				int n2 = sc.nextInt();
				
				switch(ch)
				{
				case '+':
					res = n1 + n2;
					System.out.println(res);
					break;
					
				case '-':
					res = n1 - n2;
					System.out.println(res);
					break;
					
				case '*':
					res = n1 * n2;
					System.out.println(res);
					break;
					
				case '/':
					res = n1 / n2;
					System.out.println(res);
					break;
					
				case '%':
					res = n1 % n2;
					System.out.println(res);
					break;
				}
				
			}
			else{
				System.out.println("Invalid operation. Try again.");
			}
		}
		while(ch != 'X' && ch != 'x');
		sc.close();
	}

}

Hey @shatarupa2509_6702bcc43c339df9 There is slight silly mistake in your code which is you haven’t updated ch after the operation is executed that your ch is always ‘*’( for the sample test case) so you have to update ch after else statement like this :

else{
	System.out.println("Invalid operation. Try again.");
}
ch = sc.next().charAt(0);

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.