What should I do to make the code repet itself until there is no value in ch

import java.util.;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
char ch = sc.next().charAt(0);
//while(ch!=0){
int a = sc.nextInt();
int b = sc.nextInt();
int result=0;
//do
switch(ch){
case β€˜x’:
break;
case β€˜X’:
break;
case β€˜+’:
result = a+b;
System.out.println(result);
break;
case β€˜-’:
result=a-b;
System.out.println(result);
break;
case '
’:
result=a*b;
System.out.println(result);
break;
case β€˜%’:
result = a%b;
System.out.println(result);
break;
case β€˜/’:
result=a/b;
System.out.println(result);
break;
default:
System.out.println("'Invalid operation. Try again");
break;

	}//while(true);
	}

}

}

@mishikasrvastava,
use a do-while loop.

in case the input char is +,-,*,/,% input numbers. In case the input is not x or X print invalid operation. The while loop condition will be:

do
       {

        } while (ch != 'x' && ch != 'X');

also declare ch as char outside the loop, else you might get an error

Exception in thread β€œmain” java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:864) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at Main.main(Main.java:7)

how to resolve this error

@mishikasrvastava,
Can you please share your code?

An input mismatch exception usually occurs when you try to store an int input in a char or vice-versa. Basically when the input doesn’t match the variable data type

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.

2 2 5 Invalid Operation.Try again Invalid Operation.Try again