|
@@ -17,7 +17,7 @@ public class StringUtilities {
|
17
|
17
|
* @return the concatenation of two strings, `firstSegment`, and `secondSegment`
|
18
|
18
|
*/
|
19
|
19
|
public static String concatenation(String firstSegment, String secondSegment){
|
20
|
|
- return firstSegment.concat(secondSegment);
|
|
20
|
+ return firstSegment + secondSegment;
|
21
|
21
|
}
|
22
|
22
|
|
23
|
23
|
/**
|
|
@@ -42,7 +42,7 @@ public class StringUtilities {
|
42
|
42
|
* @return the last 3 characters of `input`
|
43
|
43
|
*/
|
44
|
44
|
public static String getSuffix(String input){
|
45
|
|
- return input.substring(0,-3);
|
|
45
|
+ return input.substring(input.length()-3, input.length());
|
46
|
46
|
|
47
|
47
|
}
|
48
|
48
|
|
|
@@ -52,7 +52,7 @@ public class StringUtilities {
|
52
|
52
|
* @return the equivalence of two strings, `inputValue` and `comparableValue`
|
53
|
53
|
*/
|
54
|
54
|
public static Boolean compareTwoStrings(String inputValue, String comparableValue){
|
55
|
|
- return true;
|
|
55
|
+ return inputValue.equalsIgnoreCase(comparableValue);
|
56
|
56
|
}
|
57
|
57
|
|
58
|
58
|
/**
|
|
@@ -60,7 +60,18 @@ public class StringUtilities {
|
60
|
60
|
* @return the middle character of `inputValue`
|
61
|
61
|
*/
|
62
|
62
|
public static Character getMiddleCharacter(String inputValue){
|
63
|
|
- return getMiddleCharacter(inputValue);
|
|
63
|
+ int length;
|
|
64
|
+ int position;
|
|
65
|
+ if (inputValue.length() % 2 ==0) {
|
|
66
|
+ position = inputValue.length()/2-1;
|
|
67
|
+ length = 2;
|
|
68
|
+
|
|
69
|
+ } else {
|
|
70
|
+ position = inputValue.length()/2;
|
|
71
|
+ length = 1;
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ return inputValue.charAt(position);
|
64
|
75
|
}
|
65
|
76
|
|
66
|
77
|
/**
|
|
@@ -68,7 +79,15 @@ public class StringUtilities {
|
68
|
79
|
* @return the first sequence of characters
|
69
|
80
|
*/
|
70
|
81
|
public static String getFirstWord(String spaceDelimitedString){
|
71
|
|
- return getFirstWord(spaceDelimitedString);
|
|
82
|
+
|
|
83
|
+ String answer = "";
|
|
84
|
+
|
|
85
|
+ for (int i = 0; i< spaceDelimitedString.length(); i++){
|
|
86
|
+ if (spaceDelimitedString.charAt(i) == ' ') {
|
|
87
|
+ answer = spaceDelimitedString.substring(0, i);
|
|
88
|
+ }
|
|
89
|
+ }
|
|
90
|
+ return answer;
|
72
|
91
|
}
|
73
|
92
|
|
74
|
93
|
/**
|
|
@@ -76,14 +95,25 @@ public class StringUtilities {
|
76
|
95
|
* @return the second word of a string delimited by spaces.
|
77
|
96
|
*/
|
78
|
97
|
public static String getSecondWord(String spaceDelimitedString){
|
79
|
|
- return getSecondWord(spaceDelimitedString);
|
|
98
|
+
|
|
99
|
+ String[] answer = spaceDelimitedString.split(" ");
|
|
100
|
+
|
|
101
|
+ return answer[1];
|
80
|
102
|
}
|
81
|
103
|
|
|
104
|
+
|
|
105
|
+
|
82
|
106
|
/**
|
83
|
107
|
* @param stringToReverse
|
84
|
108
|
* @return an identical string with characters in reverse order.
|
85
|
109
|
*/
|
86
|
110
|
public static String reverseTheTwo(String stringToReverse){
|
87
|
|
- return reverseTheTwo(stringToReverse);
|
|
111
|
+ String answer = "";
|
|
112
|
+
|
|
113
|
+ for (int i = stringToReverse.length()-1; i >= 0; i--) {
|
|
114
|
+ answer = answer + stringToReverse.charAt(i);
|
|
115
|
+ }
|
|
116
|
+
|
|
117
|
+ return answer;
|
88
|
118
|
}
|
89
|
119
|
}
|