Browse Source

last try commit

Carolynn Vansant 6 years ago
parent
commit
a5c2793b98

+ 5
- 7
src/main/java/com/zipcodewilmington/danny_do_better_exercises/StringUtilities.java View File

68
     public static Character getMiddleCharacter(String inputValue){
68
     public static Character getMiddleCharacter(String inputValue){
69
         int str = inputValue.length();
69
         int str = inputValue.length();
70
 
70
 
71
-        return inputValue.charAt(str / 2);
71
+        return inputValue.charAt(Math.round(str / 2));
72
+
72
     }
73
     }
73
 
74
 
74
     /**
75
     /**
85
      * @return the second word of a string delimited by spaces.
86
      * @return the second word of a string delimited by spaces.
86
      */
87
      */
87
     public static String getSecondWord(String spaceDelimitedString){
88
     public static String getSecondWord(String spaceDelimitedString){
88
-        int spacer = spaceDelimitedString.lastIndexOf(" ");
89
-        return spaceDelimitedString.substring(spacer);
89
+        int spacer = spaceDelimitedString.indexOf(" ");
90
+        return spaceDelimitedString.substring(spacer + 1, spaceDelimitedString.length());
90
     }
91
     }
91
 
92
 
92
     /**
93
     /**
94
      * @return an identical string with characters in reverse order.
95
      * @return an identical string with characters in reverse order.
95
      */
96
      */
96
 
97
 
97
-    public static String reverseTheTwo(String stringToReverse) {
98
+    public static String reverse(String stringToReverse) {
98
         String reverse = "";
99
         String reverse = "";
99
         for (int i = stringToReverse.length() - 1; i >= 0; i--) {
100
         for (int i = stringToReverse.length() - 1; i >= 0; i--) {
100
             reverse += stringToReverse.charAt(i);
101
             reverse += stringToReverse.charAt(i);
102
         return reverse;
103
         return reverse;
103
     }
104
     }
104
 
105
 
105
-    public static String reverse(String stringToReverse){
106
-        return null;
107
 
106
 
108
-    }
109
 }
107
 }