Hello here is some code to check for a valid character, although the code is not working. Even if 'operand' is a valid character it will never print yes, and return false. No matter what even if the character is valid it just doesn't recognize it and always goes to the else statement. Please help!
public static boolean checkValidOperands(char operand) {
char[] validOperators = {'+', '-', '*', '/', 'q'};
List<char[]> validOp = Arrays.asList(validOperators);
if (validOp.contains(operand)) {
System.out.println("Yes");
return false;
} else {
System.out.println("Please enter valid operand");
return true;
}
}
You could use:
List<Character> validOp = Arrays.asList('+', '-', '*', '/', 'q');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With