StringUtilities.java 747B

1234567891011121314151617181920212223242526272829
  1. public class StringUtilities {
  2. public Character getMiddleCharacter(String word){
  3. char result;
  4. int length = word.length();
  5. if(length%2 == 1){ //odd
  6. result = word.charAt((length-1)/2);
  7. } else { //even
  8. result = word.charAt((length/2));
  9. }
  10. return result;
  11. }
  12. public String removeCharacter(String value, char charToRemove){
  13. String strToRemove = Character.toString(charToRemove);
  14. String result = value.replace(strToRemove,"");
  15. return result;
  16. }
  17. public String getLastWord(String value) {
  18. String[] strArray = value.split(" ");
  19. String result = strArray[strArray.length-1];
  20. return result;
  21. }
  22. }