Просмотр исходного кода

added methods up to remove consecutive duplictes

mpierse 8 лет назад
Родитель
Сommit
44ddef123b
1 измененных файлов: 39 добавлений и 26 удалений
  1. 39
    26
      src/main/java/com/zipcodewilmington/StringArrayUtils.java

+ 39
- 26
src/main/java/com/zipcodewilmington/StringArrayUtils.java Просмотреть файл

@@ -76,8 +76,9 @@ public class StringArrayUtils {
76 76
      * @return true if the order of the array is the same backwards and forwards
77 77
      */ // TODO
78 78
     public static boolean isPalindromic(String[] array) {
79
-
80
-        return Arrays.equals(array, reverse(array));
79
+       String[] arrHolder = new String[array.length];
80
+        System.arraycopy(array, 0, arrHolder, 0, array.length);
81
+        return Arrays.equals(arrHolder, reverse(array));
81 82
     }
82 83
 
83 84
     /**
@@ -85,21 +86,32 @@ public class StringArrayUtils {
85 86
      * @return true if each letter in the alphabet has been used in the array
86 87
      */  //TODO
87 88
     public static boolean isPangramic(String[] array) {
89
+
90
+        boolean[] panagramic = new boolean[26];
91
+        for (boolean bool : panagramic) {bool=false;}
92
+        boolean result = true;
88 93
         String concatString = "";
89
-        String alphabet = "qwertyuiopasdfghjklzxcvbnm";
90
-        boolean panagramic = true;
91
-        for (int i=0; i<array.length; i++){
94
+        for(int i=0; i<array.length; i++) {
92 95
             concatString += array[i];
93 96
         }
94
-        char[] alphArr = alphabet.toCharArray();
95
-        for (int i=0; i<alphabet.length(); i++){
97
+        concatString = concatString.toLowerCase();
98
+
99
+        for (int i=0; i<concatString.length(); i++) {
100
+
101
+            char holder = concatString.charAt(i);
102
+            if((int)holder>=97 && (int)holder<=122){
103
+           panagramic[(int)holder-97]= true;
104
+           System.out.print(holder);
105
+        }}
106
+
107
+        for (boolean bool : panagramic){
108
+            if(bool==true)
109
+            { continue;}
110
+            else {result=false;
111
+            break;}
96 112
 
97
-            if (concatString.indexOf(alphArr[i])<0){
98
-                panagramic = false;
99
-                break;
100
-            }
101 113
         }
102
-        return panagramic;
114
+        return result;
103 115
     }
104 116
 
105 117
     /**
@@ -108,10 +120,10 @@ public class StringArrayUtils {
108 120
      * @return number of occurrences the specified `value` has occurred
109 121
      */ // TODO
110 122
     public static int getNumberOfOccurrences(String[] array, String value) {
111
-       int counter=0;
123
+int counter = 0;
112 124
         for (int i=0; i<array.length; i++) {
113 125
             if (array[i].equals(value)){
114
-                counter++;
126
+counter++;
115 127
             }
116 128
         }
117 129
         return counter;
@@ -123,17 +135,16 @@ public class StringArrayUtils {
123 135
      * @param valueToRemove value to remove from array
124 136
      * @return array with identical contents excluding values of `value`
125 137
      */ // TODO
126
-    public static String[] removeValue(String[] array, String valueToRemove) {
127
-        int valueCount = getNumberOfOccurrences(array, valueToRemove);
128
-        String[] arrayMinusValue = new String[array.length-valueCount];
129
-        int counter = 0;
130
-        for(int i=0; i<array.length; i++){
131
-            if (!array[i].equals(valueToRemove)){
132
-                array[i]=arrayMinusValue[counter];
133
-                counter++;
134
-            }
135
-        }
136
-        return arrayMinusValue;
138
+   public static String[] removeValue(String[] array, String valueToRemove) {
139
+       int count = getNumberOfOccurrences(array, valueToRemove);
140
+       String[] tempArr = new String[array.length-count];
141
+       int iterator = 0;
142
+       for (int i=0; i<array.length; i++){
143
+           if (!array[i].equals(valueToRemove)){
144
+               tempArr[iterator++] = array[i];
145
+           }
146
+       }
147
+       return tempArr;
137 148
     }
138 149
 
139 150
     /**
@@ -141,7 +152,9 @@ public class StringArrayUtils {
141 152
      * @return array of Strings with consecutive duplicates removes
142 153
      */ // TODO
143 154
     public static String[] removeConsecutiveDuplicates(String[] array) {
144
-        return null;
155
+
156
+        
157
+
145 158
     }
146 159
 
147 160
     /**