What is wrong in my code

main{

	BasicCAlculator();
}
public static void BasicCAlculator() {
	while(true) {
		char ch=scn.next().charAt(0);
	if(ch=='X'||ch=='x') {
		System.exit(1);
		}else if(ch=='+'||ch=='-'||ch=='*'||ch=='/'||ch=='%') {
			int num1=scn.nextInt();
			int num2=scn.nextInt();
			switch(ch) {
			case '+':
				System.out.println(num1+num2);
				break;
			case '-':
				System.out.println(num1-num2);
				break;
			case '/':
				System.out.println(num1/num2);
				break;
			case '*':
				System.out.println(num1*num2);
				break;
			case '%':
				System.out.println(num1%num2);
			}
		}else {
			System.out.println("Invalid operation. Try again.");
			BasicCAlculator();
		}
}

}
//////////////////////////////////////////
it is showing run error,but when I am removing the while loop in am getting 2 run error,1 correct answer,remaining wrong answer.
please help

@ubaidshaikh9999,
Here is the correct code https://ide.codingblocks.com/s/187131
Mistakes:

  1. In the else part, you don’t need to call the BasicCAlculator(); function again.
  2. Instead of using System.exit(1); use return; because BasicCAlculator() is another function. So the main function is still in the stack and you cannot exit the code from BasicCAlculator().

Also, start using https://ide.codingblocks.com/ to share your code. And share your complete code.

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.