StringUtilities.java 831B

12345678910111213141516171819202122232425262728293031
  1. public class StringUtilities {
  2. public Character getMiddleCharacter(String word){
  3. char wordResult = 'a';
  4. if (word.length()%2 == 1) {
  5. int oddLength = word.length()/2;
  6. int evenLength = word.length()/2-1;
  7. // wordResult = word.substring(oddLength, oddLength + 1);
  8. }
  9. else {
  10. // wordResult = word.substring(evenLength, evenlength + 1);
  11. }
  12. return wordResult;
  13. }
  14. public String removeCharacter(String value, char charToRemove){
  15. String newString = "";
  16. for (int i = 0; i < value.length(); i ++) {
  17. if (value.charAt(i) != charToRemove) newString += value.charAt(i);
  18. }
  19. return newString;
  20. }
  21. public String getLastWord(String value) {
  22. return value.substring(value.lastIndexOf(" ")+1);
  23. }
  24. }