StringUtilities.java 841B

123456789101112131415161718192021222324252627282930
  1. public class StringUtilities {
  2. public Character getMiddleCharacter(String word){
  3. int value=0;
  4. char middle=0;
  5. if(word.length()%2==0){
  6. value=(word.length() / 2-1);
  7. middle= word.charAt(value);
  8. } else if (word.length()%2 !=0){
  9. value=(word.length() / 2);
  10. middle= word.charAt(value);
  11. }
  12. return middle;
  13. }
  14. public String removeCharacter(String value, char charToRemove){
  15. int word = value.length();
  16. String start = value.substring(0, word / 2);
  17. String end = value.substring((word / 2) + 1 , value.length());
  18. String sum= start + end;
  19. return sum;
  20. }
  21. public String getLastWord(String value) {
  22. String lastWord = value.substring(value.lastIndexOf(" ")+1);
  23. return lastWord;
  24. }
  25. }