Mexi Liang hace 8 años
padre
commit
d777f8a49c
Se han modificado 1 ficheros con 42 adiciones y 6 borrados
  1. 42
    6
      StringArrayUtils.java

+ 42
- 6
StringArrayUtils.java Ver fichero

50
      * @return true if the array contains the specified `value`
50
      * @return true if the array contains the specified `value`
51
      */ // TODO
51
      */ // TODO
52
     public static boolean contains(String[] array, String value) {
52
     public static boolean contains(String[] array, String value) {
53
-       String[] arr = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
54
-       if (Arrays.asList(arr).contains("quick") == true){
55
-        return true;
53
+        String[] arr = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
54
+        if (Arrays.asList(arr).contains("quick") == true){
55
+            return true;
56
         }
56
         }
57
         else{
57
         else{
58
         }
58
         }
59
-       return false ;
59
+        return false ;
60
     }
60
     }
61
 
61
 
62
     /**
62
     /**
64
      * @return an array with identical contents in reverse order
64
      * @return an array with identical contents in reverse order
65
      */ // TODO
65
      */ // TODO
66
     public static String[] reverse(String[] array) {
66
     public static String[] reverse(String[] array) {
67
-        return null;
67
+        for (int i=0; i<array.length/2;i++){
68
+            String temp = array[i];
69
+            array[i] = array[array.length-1-i];
70
+            array[array.length-1-i] = temp;
71
+
72
+        }
73
+
74
+        return array;
68
     }
75
     }
69
 
76
 
70
     /**
77
     /**
72
      * @return true if the order of the array is the same backwards and forwards
79
      * @return true if the order of the array is the same backwards and forwards
73
      */ // TODO
80
      */ // TODO
74
     public static boolean isPalindromic(String[] array) {
81
     public static boolean isPalindromic(String[] array) {
82
+        String[] newArr = new String[array.length]; //newArr is a copy of original array
83
+        //newArray[i] = array[array.length-i-1];
84
+        for (int i=0;i<array.length;i++){
85
+            newArr[i]=array[array.length-i-1];
86
+
87
+        }
88
+        if (Arrays.equals(newArr,array)){
89
+            return true;
90
+
91
+        }
75
         return false;
92
         return false;
93
+        
94
+        // if (array.length%2 ==0){
95
+        // for (int i=0; i<array.length/2;i++){
96
+        // String temp = array[i];
97
+        // array[i] = array[array.length-1];
98
+        // array[array.length-1] = temp;
99
+        // //reverse the original array
100
+        // }
101
+        // }
102
+        // if (Arrays.equals(newArr,array)){
103
+        // return true;
104
+        // }
105
+        // // else if(!array[0].equals(array[array.length-1])){
106
+        // // return false;
107
+        // // }
108
+        // else{    
109
+        // return false;
110
+        // }
111
+
76
     }
112
     }
77
 
113
 
78
     /**
114
     /**
80
      * @return true if each letter in the alphabet has been used in the array
116
      * @return true if each letter in the alphabet has been used in the array
81
      */ // TODO
117
      */ // TODO
82
     public static boolean isPangramic(String[] array) {
118
     public static boolean isPangramic(String[] array) {
119
+
83
         return false;
120
         return false;
84
     }
121
     }
85
 
122
 
117
         return null;
154
         return null;
118
     }
155
     }
119
 
156
 
120
-
121
 }
157
 }