Bladeren bron

new changes

Xcuello 5 jaren geleden
bovenliggende
commit
8cc4e56382

+ 0
- 2
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Bestand weergeven

24
                 hashmap.put(splitString[i], hashmap.get(splitString[i]) + 1);
24
                 hashmap.put(splitString[i], hashmap.get(splitString[i]) + 1);
25
             }
25
             }
26
         }
26
         }
27
-
28
         for (Object word : hashmap.keySet()) {
27
         for (Object word : hashmap.keySet()) {
29
 
28
 
30
             hashmap.get(word);
29
             hashmap.get(word);
31
         }
30
         }
32
-
33
         return hashmap;
31
         return hashmap;
34
 
32
 
35
     }
33
     }

+ 30
- 24
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java Bestand weergeven

9
     public static Character getMiddleCharacter(String string) {
9
     public static Character getMiddleCharacter(String string) {
10
 
10
 
11
         int halfLength = string.length() / 2;
11
         int halfLength = string.length() / 2;
12
-        Character midChar;
12
+        char midChar;
13
 
13
 
14
         if (halfLength % 2 == 0) {
14
         if (halfLength % 2 == 0) {
15
 
15
 
25
 
25
 
26
     public static String capitalizeMiddleCharacter(String str) {
26
     public static String capitalizeMiddleCharacter(String str) {
27
 
27
 
28
-        return getMiddleCharacter(str).toString().toUpperCase();
28
+        char[] charArray = str.toCharArray();
29
+
30
+        charArray[charArray.length / 2] = Character.toUpperCase(charArray[charArray.length / 2]);
31
+        String newStr = new String(charArray);
32
+
33
+        return newStr;
29
     }
34
     }
30
 
35
 
31
     public static String lowerCaseMiddleCharacter(String str) {
36
     public static String lowerCaseMiddleCharacter(String str) {
32
 
37
 
33
-        return getMiddleCharacter(str).toString().toLowerCase();
38
+        char[] charArray = str.toCharArray();
39
+
40
+        charArray[charArray.length / 2] = Character.toLowerCase(charArray[charArray.length / 2]);
41
+        String newStr = new String(charArray);
42
+
43
+        return newStr;
34
     }
44
     }
35
 
45
 
36
     public static Boolean isIsogram(String str) {
46
     public static Boolean isIsogram(String str) {
50
 
60
 
51
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
61
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
52
 
62
 
53
-        for (int i = 0; i < str.length(); i++) {
63
+        for (int i = 1; i < str.length(); i++) {
54
 
64
 
55
-            if (str.charAt(i) == str.charAt(i)) ;
65
+            if (str.charAt(i) == str.charAt(i - 1))
56
 
66
 
57
             return true;
67
             return true;
58
         }
68
         }
61
 
71
 
62
     public static String removeConsecutiveDuplicateCharacters(String str) {
72
     public static String removeConsecutiveDuplicateCharacters(String str) {
63
 
73
 
64
-        int position = 1;
65
-        char[] chars = str.toCharArray();
66
-
67
-        for (int i = 0; i < str.length(); i++) {
74
+       StringBuilder sb = new StringBuilder();
75
+       String[] array = str.split("");
76
+       String letter = array[0];
68
 
77
 
69
-            for (int j = 0; j < position; j++) {
78
+        for (int i = 1; i < array.length; i++) {
79
+            String nextLetter = array[i];
70
 
80
 
71
-                if (chars[i] == chars[j]) {
81
+            if(letter.equals(nextLetter)) {
82
+                array[i] = "";
83
+                array[i - 1] = "";
72
 
84
 
73
-                    break;
74
-                }
85
+            }else{
75
 
86
 
76
-                if (j == position) {
77
-
78
-                    chars[position] = chars[i];
79
-                    position++;
80
-
81
-                } else {
82
-
83
-                    chars[position] = 0;
84
-                    position++;
85
-                }
87
+                letter = array[i];
86
             }
88
             }
87
         }
89
         }
88
 
90
 
89
-        return str;
91
+        for(String s : array) {
92
+            sb.append(s);
93
+        }
94
+
95
+        return sb.toString();
90
     }
96
     }
91
 
97
 
92
     public static String invertCasing(String str) {
98
     public static String invertCasing(String str) {