xxxxxxxxxx
If your input is a character and the characters you are checking against are mostly consecutive you could try this:
if ((symbol >= 'A' && symbol <= 'Z') || symbol == '?') {
// ...
}
xxxxxxxxxx
public class JavaCharacterCompareExample1 {
public static void main(String[] args) {
char firstValue = 'A';
char secondValue = 'B';
// compare the first char to the second
int compareOneTwo = Character.compare(firstValue, secondValue);
if (compareOneTwo> 0) {
System.out.println("First value is greater than second value");
}
else {
System.err.println("First value is less than second value.");
}
}
}
// OUT: First value is less than the second value.
xxxxxxxxxx
char char1 = 'a';
char char2 = 'b';
// Comparing characters using relational operators
boolean equal = (char1 == char2);
boolean greaterThan = (char1 > char2);
boolean lessThan = (char1 < char2);
// Comparing characters using compareTo method
int comparisonResult = Character.compare(char1, char2);
xxxxxxxxxx
char char1 = 'a';
char char2 = 'b';
if (char1 == char2) {
System.out.println("Characters are equal");
} else {
System.out.println("Characters are not equal");
}