Browse Source

new changes

Xcuello 5 years ago
parent
commit
8cc4e56382

+ 0
- 2
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java View File

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

+ 30
- 24
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java View File

@@ -9,7 +9,7 @@ public class StringUtils {
9 9
     public static Character getMiddleCharacter(String string) {
10 10
 
11 11
         int halfLength = string.length() / 2;
12
-        Character midChar;
12
+        char midChar;
13 13
 
14 14
         if (halfLength % 2 == 0) {
15 15
 
@@ -25,12 +25,22 @@ public class StringUtils {
25 25
 
26 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 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 46
     public static Boolean isIsogram(String str) {
@@ -50,9 +60,9 @@ public class StringUtils {
50 60
 
51 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 67
             return true;
58 68
         }
@@ -61,32 +71,28 @@ public class StringUtils {
61 71
 
62 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 98
     public static String invertCasing(String str) {