StringUtilities.java 744B

12345678910111213141516171819202122232425262728
  1. package QuizWeek1;
  2. public class StringUtilities {
  3. public Character getMiddleCharacter(String word){
  4. int middleChar;
  5. if ((word.length()/2)%2 == 0){
  6. middleChar = word.length()/2+1;
  7. }else{
  8. middleChar = Math.round(word.length()/2);
  9. }
  10. return word.charAt(middleChar);
  11. }
  12. public String removeCharacter(String value, char charToRemove){
  13. int removeChar = value.indexOf(charToRemove);
  14. return value.substring(0,removeChar) + value.substring(removeChar+1);
  15. }
  16. public String getLastWord(String value) {
  17. int indexLastWord = value.lastIndexOf(" ");
  18. return value.substring(indexLastWord+1);
  19. }
  20. }