|
@@ -1,23 +1,45 @@
|
1
|
1
|
package rocks.zipcode.quiz5.fundamentals;
|
2
|
2
|
|
|
3
|
+import java.util.*;
|
|
4
|
+
|
3
|
5
|
/**
|
4
|
6
|
* @author leon on 21/12/2018.
|
5
|
7
|
*/
|
6
|
8
|
public class StringUtils {
|
7
|
9
|
public static Character getMiddleCharacter(String string) {
|
8
|
|
- return null;
|
|
10
|
+ return string.charAt(string.length()/2);
|
9
|
11
|
}
|
10
|
12
|
|
11
|
13
|
public static String capitalizeMiddleCharacter(String str) {
|
12
|
|
- return null;
|
|
14
|
+ int middle = str.length()/2;
|
|
15
|
+ String upper = str.substring(middle, middle+1).toUpperCase();
|
|
16
|
+ String[] strArray = str.split("");
|
|
17
|
+ strArray[middle] = upper;
|
|
18
|
+ String fin = "";
|
|
19
|
+ for(String string : strArray){
|
|
20
|
+ fin = fin.concat(string);
|
|
21
|
+ }
|
|
22
|
+ return fin;
|
|
23
|
+
|
13
|
24
|
}
|
14
|
25
|
|
15
|
26
|
public static String lowerCaseMiddleCharacter(String str) {
|
16
|
|
- return null;
|
|
27
|
+ int middle = str.length()/2;
|
|
28
|
+ String upper = str.substring(middle, middle+1).toLowerCase();
|
|
29
|
+ String[] strArray = str.split("");
|
|
30
|
+ strArray[middle] = upper;
|
|
31
|
+ String fin = "";
|
|
32
|
+ for(String string : strArray){
|
|
33
|
+ fin = fin.concat(string);
|
|
34
|
+ }
|
|
35
|
+ return fin;
|
17
|
36
|
}
|
18
|
37
|
|
19
|
38
|
public static Boolean isIsogram(String str) {
|
20
|
|
- return null;
|
|
39
|
+ Set<Character> set = new HashSet<>();
|
|
40
|
+ for(int i = 0; i < str.length(); i++) set.add(str.charAt(i));
|
|
41
|
+ if(set.size() == str.length()) return true;
|
|
42
|
+ return false;
|
21
|
43
|
}
|
22
|
44
|
|
23
|
45
|
public static Boolean hasDuplicateConsecutiveCharacters(String str) {
|
|
@@ -25,10 +47,39 @@ public class StringUtils {
|
25
|
47
|
}
|
26
|
48
|
|
27
|
49
|
public static String removeConsecutiveDuplicateCharacters(String str) {
|
28
|
|
- return null;
|
|
50
|
+ boolean isContinued = true;
|
|
51
|
+ String[] strArray = str.split("");
|
|
52
|
+ String fin = "";
|
|
53
|
+ while(isContinued){
|
|
54
|
+ //if(strArray)
|
|
55
|
+ }
|
|
56
|
+ return fin;
|
29
|
57
|
}
|
30
|
58
|
|
31
|
59
|
public static String invertCasing(String str) {
|
32
|
|
- return null;
|
|
60
|
+ String[] strArray = str.split("");
|
|
61
|
+ String fin = "";
|
|
62
|
+ for(String string : strArray){
|
|
63
|
+ if(isUpperCase(string)){
|
|
64
|
+ String temp = string.toLowerCase();
|
|
65
|
+ fin = fin.concat(temp);
|
|
66
|
+ }
|
|
67
|
+ else if(!isUpperCase(string)){
|
|
68
|
+ String temp = string.toUpperCase();
|
|
69
|
+ fin = fin.concat(temp);
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ return fin;
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ public static boolean isUpperCase(String s) {
|
|
76
|
+ for (int i=0; i<s.length(); i++)
|
|
77
|
+ {
|
|
78
|
+ if (Character.isLowerCase(s.charAt(i)))
|
|
79
|
+ {
|
|
80
|
+ return false;
|
|
81
|
+ }
|
|
82
|
+ }
|
|
83
|
+ return true;
|
33
|
84
|
}
|
34
|
85
|
}
|