Sfoglia il codice sorgente

added methods up to remove consecutive duplictes

mpierse 8 anni fa
parent
commit
44ddef123b
1 ha cambiato i file con 39 aggiunte e 26 eliminazioni
  1. 39
    26
      src/main/java/com/zipcodewilmington/StringArrayUtils.java

+ 39
- 26
src/main/java/com/zipcodewilmington/StringArrayUtils.java Vedi File

76
      * @return true if the order of the array is the same backwards and forwards
76
      * @return true if the order of the array is the same backwards and forwards
77
      */ // TODO
77
      */ // TODO
78
     public static boolean isPalindromic(String[] array) {
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
      * @return true if each letter in the alphabet has been used in the array
86
      * @return true if each letter in the alphabet has been used in the array
86
      */  //TODO
87
      */  //TODO
87
     public static boolean isPangramic(String[] array) {
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
         String concatString = "";
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
             concatString += array[i];
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
      * @return number of occurrences the specified `value` has occurred
120
      * @return number of occurrences the specified `value` has occurred
109
      */ // TODO
121
      */ // TODO
110
     public static int getNumberOfOccurrences(String[] array, String value) {
122
     public static int getNumberOfOccurrences(String[] array, String value) {
111
-       int counter=0;
123
+int counter = 0;
112
         for (int i=0; i<array.length; i++) {
124
         for (int i=0; i<array.length; i++) {
113
             if (array[i].equals(value)){
125
             if (array[i].equals(value)){
114
-                counter++;
126
+counter++;
115
             }
127
             }
116
         }
128
         }
117
         return counter;
129
         return counter;
123
      * @param valueToRemove value to remove from array
135
      * @param valueToRemove value to remove from array
124
      * @return array with identical contents excluding values of `value`
136
      * @return array with identical contents excluding values of `value`
125
      */ // TODO
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
      * @return array of Strings with consecutive duplicates removes
152
      * @return array of Strings with consecutive duplicates removes
142
      */ // TODO
153
      */ // TODO
143
     public static String[] removeConsecutiveDuplicates(String[] array) {
154
     public static String[] removeConsecutiveDuplicates(String[] array) {
144
-        return null;
155
+
156
+        
157
+
145
     }
158
     }
146
 
159
 
147
     /**
160
     /**