|
@@ -1,5 +1,7 @@
|
1
|
1
|
package com.zipcodewilmington.danny_do_better_exercises;
|
2
|
2
|
|
|
3
|
+import java.util.Arrays;
|
|
4
|
+
|
3
|
5
|
/**
|
4
|
6
|
* Created by dan on 6/14/17.
|
5
|
7
|
*/
|
|
@@ -59,16 +61,9 @@ public class StringUtilities {
|
59
|
61
|
* @return the middle character of `inputValue`
|
60
|
62
|
*/
|
61
|
63
|
public static Character getMiddleCharacter(String inputValue){
|
62
|
|
- String outputValue = inputValue;
|
63
|
|
- int position;
|
64
|
|
- if(inputValue.length() %2 == 0) {
|
65
|
|
- position = inputValue.length() / 2 -1;
|
66
|
|
- return outputValue();
|
67
|
|
- }else {
|
68
|
|
- position = inputValue.length()/ 2;
|
69
|
|
- }
|
70
|
|
- return
|
71
|
|
-
|
|
64
|
+ int lenWord = inputValue.length()-1;
|
|
65
|
+ int midChar = (int)(Math.floor(lenWord/2));
|
|
66
|
+ return inputValue.charAt(midChar);
|
72
|
67
|
}
|
73
|
68
|
|
74
|
69
|
/**
|
|
@@ -76,7 +71,9 @@ public class StringUtilities {
|
76
|
71
|
* @return the first sequence of characters
|
77
|
72
|
*/
|
78
|
73
|
public static String getFirstWord(String spaceDelimitedString){
|
79
|
|
- return null;
|
|
74
|
+ String words = spaceDelimitedString;
|
|
75
|
+ String[] splitString = spaceDelimitedString.trim().split("\\s+");
|
|
76
|
+ return splitString[0];
|
80
|
77
|
}
|
81
|
78
|
|
82
|
79
|
/**
|
|
@@ -84,7 +81,11 @@ public class StringUtilities {
|
84
|
81
|
* @return the second word of a string delimited by spaces.
|
85
|
82
|
*/
|
86
|
83
|
public static String getSecondWord(String spaceDelimitedString){
|
87
|
|
- return null;
|
|
84
|
+
|
|
85
|
+ String[] words = spaceDelimitedString.trim().split(" ");
|
|
86
|
+ String second = words[1];
|
|
87
|
+ return second;
|
|
88
|
+
|
88
|
89
|
}
|
89
|
90
|
|
90
|
91
|
/**
|
|
@@ -92,6 +93,6 @@ public class StringUtilities {
|
92
|
93
|
* @return an identical string with characters in reverse order.
|
93
|
94
|
*/
|
94
|
95
|
public static String reverseTheTwo(String stringToReverse){
|
95
|
|
- return null;
|
|
96
|
+ return new StringBuilder(stringToReverse).reverse().toString();
|
96
|
97
|
}
|
97
|
98
|
}
|