No need to deal with it character by character or use substring etc. Basic regex will suffice. I'll leave it up to you to figure out how to read from keyboard etc.
Code:
public class Test {
public static void main(String[] args) {
try {
String s = "This is a sentence. Here is a comma ','. And a question mark '?'. And some more crap: ,.:;'?!\"()";
System.out.println("Before: " + s);
s = s.replaceAll("[,.:;'?!\"()]", "");
System.out.println("After: " + s);
} catch (Exception e) {
e.printStackTrace();
}
}
}
PS. There are more punctuation characters than you have listed but I have just used the ones you mentioned.
Bookmarks