Answer:
Explanation:
The following code is written in Java. It creates the UnknownOperatorException class and catches it if the user enters something other than the valid operators. If so it continues asking the user for a new input. Once a valid operator is entered, it exits the function and prints the operator.
import java.util.Scanner;
class Brainly {
public static void main(String[] args) {
char symbol = askForOperand();
System.out.println("Operand: " + symbol);
}
public static char askForOperand() {
Scanner in = new Scanner(System.in);
try {
System.out.println("Enter operator symbol: ");
char symbol = in.nextLine().charAt(0);
if ((symbol != '-') && (symbol != '*') && (symbol != '/')) {
System.out.println(symbol);
throw new UnknownOperatorException();
} else {
return symbol;
}
} catch (NumberFormatException | UnknownOperatorException e) {
System.out.println("Not a valid operand");
char symbol = askForOperand();
return symbol;
}
}
}
class UnknownOperatorException extends Exception {
public UnknownOperatorException() {
System.out.println("Unknown Operator");
}
}