123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package QuizWeek1;
-
- public class StringUtilities {
- public Character getMiddleCharacter(String word){
- char middle;
- int mid;
- String midString = "";
-
- //find index of middle letter
- mid = ((word.length())/2);
- System.out.println(mid);
-
- //midString = word.substring(mid, (mid+1));
- middle = word.charAt(mid);
-
- // char[] charArray = word.toCharArray();
-
- // middle = charArray[mid];
- //System.out.println(middle);
-
- return middle;
- }
-
- public String removeCharacter(String value, char charToRemove){
- String newWord = value.substring(0, charToRemove-1) + value.substring((charToRemove-1) + 1);
- System.out.println(newWord);
- return newWord;
- }
-
- public String getLastWord(String value) {
- int i = 0;
- int pos;
-
- int len = (value.length()-1);
- System.out.println(len);
- int count = len;
-
- char[] charArray = value.toCharArray();
-
- //loop through until find last space
- while (charArray[count] != ' '){
-
- count--;
-
- }
-
- String last = value.substring(count + 1);
- System.out.println(last);
-
-
- return last;
- }
- }
|