After someone inputs a text file, I have to make it so it will read the text file that the user inputted.
Using a switch statement, how do I make sure the first word and last word doesn’t have a specific character?
The first word should not have a single-quotation mark, double-quotation mark, a dollar sign, or a period.
The last word should not have a single-quotation mark, double-quotation mark, semi-colon, colon, period, comma, hyphen, exclamation point, or question mark remove it.
I am using hasNext in my while so that it prints each word on one line.
Once you read in your first word you can call this function (passing in the first word as your parameter), it will return true if the word contains any illegal characters. You could then easily create another one to test your last word against.
To test the last word you could use this structure
You could also replace containsIllegalChar function by testing your string against a nice regex. E.g
Result:
Hope this helps.
Phil