Write in Java and explain all the code.
Have a unit test implemented in the main method.
Show example of the execution
Write a filter to clean a text, which is to say to delete all the
characters that are not alphabetic, plans or a newline. And besides
deleting them they should all also be replaced with a blank spot,
so that the number of characters are still the same as the text
before it was cleaned.
If you have any doubts, please give me comment...
public class FilterText{
public static void main(String[] args) {
String result = filter("Hi! th#s is test!ng!");
System.out.println(result);
}
public static String filter(String str){
String result = "";
for(int i=0; i<str.length(); i++){
if(Character.isAlphabetic(str.charAt(i)))
result += str.charAt(i);
else
result += " ";
}
return result;
}
}
Get Answers For Free
Most questions answered within 1 hours.