import java.util.*;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
// Your Code Here
boolean flag=true;
do {
Scanner s=new Scanner(System.in);
char n = s.next().charAt(0);
switch(n) {
case '+':
int num1=s.nextInt();
int num2=s.nextInt();
System.out.println(num1+num2);
break;
case '-':
num1=s.nextInt();
num2=s.nextInt();
System.out.println(num1-num2);
break;
case '*':
num1=s.nextInt();
num2=s.nextInt();
System.out.println(num1*num2);
break;
case '/':
num1=s.nextInt();
num2=s.nextInt();
System.out.println(num1/num2);
break;
case '%':
num1=s.nextInt();
num2=s.nextInt();
System.out.println(num1%num2);
break;
case 'x':
flag=false;
break;
case 'X':
flag=false;
break;
default :{
System.out.println("Invalid operation. Try again.");
break;
}
}
}while(flag==true);
}
}
Error is :
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:9)
Why this error occur? How can I resolve it