0

Char Validation

I need help. I want to make another method that says: if the character entered in the list, SA[n], is not A, B, C, D, or X, the program should stop[System.exit(0)]. i want the SA[n] list to only be able to accept A or B or C or D or X. https://code.sololearn.com/cDsmm2bB5Yy3/?ref=app

3rd Feb 2022, 10:31 PM
Bobby Dike
Bobby Dike - avatar
1 Resposta
+ 3
You can use an if statement to check if the char is in the character range 'A' through 'D' or is equal to 'X'. if(ch >= 'A' && ch <= 'D' || ch == 'X') { ... true case statement(s) } else { ... false case statements }
4th Feb 2022, 12:45 AM
ChaoticDawg
ChaoticDawg - avatar