Question: How would this be coded in java not using loops? The goal is below: public boolean validateChar(char ch) This method takes a character, and validates
How would this be coded in java not using loops?
The goal is below:
public boolean validateChar(char ch)
This method takes a character, and validates that it is one of the allowed characters in the input string. It returns true if it is, and false otherwise.
With constraints:
Your code must handle quite a bit of error checking. The strings being passed in must:
- include only the characters '4', '2' and '_',
- have exactly a length of three.
If any input string is not formatted according to this, you must return the string, unmodified.
Example Assertions:
assert validateChar('2') : "2 should be a valid char"; assert validateChar('4') : "4 should be a valid char"; assert validateChar('_') : "_ should be a valid char"; assert !validateChar(' ') : "space should not be a valid char"; assert !validateChar('3') : "3 should not be a valid char"; Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
