Basic Calculator error -----> Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1371) at Main.main(Main.java:11)

import java.util.*;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Long a,b;

	do {
		Scanner scn  = new Scanner(System.in);
		char ch;
		ch = scn.next().charAt(0);
		if( (ch =='X' || ch == 'x'))
		{break;
		}
		else if ((ch=='+' || ch=='-' || ch=='*' || ch=='/' || ch=='%')) {
			a= scn.nextLong();
			b= scn.nextLong();
			Long c = null;
			
			switch(ch) {
			case '+':c=a+b;
			break;
			case '-':c=a-b;
			break;
			case '*':c=a*b;
			break;
			case '/':c=a/b;
			break;
			case '%':c=a%b;
			break;
			}
			
			System.out.println(c);
	
		}else {
			System.out.println("Invalid operation. Try again.");
		}

	}
	while(true);
}

}

Hey @anktre7 You have to make a default case in switch to stop the code if a invalid operation is encountered.

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.