Considering
The punctuation mark is always at the end
You can get the punctuation mark from the inputWord
as following:
String punctuation = inputWord.substring(inputWord.length() - 1);
and check it using regex if it is one of the punctuation mark you should have
if (punctuation.matches("[\\!\\,\\?\\;\\.]"))
// your actions items here
this way you can avoid multiple if
statements.
Alternatively
You can maintain a set of all the punctuation marks you need to check against:
Set<String> punctuationSet = new HashSet<String>(
Arrays.asList(new String[]{"!", "?", ";", ",", "."}));
and later check if the punctuation
in the inputWord
is present in the punctuationSet
using
if (punctuationSet.contains(punctuation))
// your actions items here