Khalil Saboor 8 年之前
父節點
當前提交
1a304c7785
共有 2 個文件被更改,包括 84 次插入7 次删除
  1. 42
    7
      StringArrayUtils.java
  2. 42
    0
      package.bluej

+ 42
- 7
StringArrayUtils.java 查看文件

@@ -9,7 +9,7 @@ public class StringArrayUtils {
9 9
      * @return first element of specified array
10 10
      */ // TODO
11 11
     public static String getFirstElement(String[] array) {
12
-        return null;
12
+        return array[0];
13 13
     }
14 14
 
15 15
     /**
@@ -17,7 +17,7 @@ public class StringArrayUtils {
17 17
      * @return second element in specified array
18 18
      */
19 19
     public static String getSecondElement(String[] array) {
20
-        return null;
20
+        return array[1];
21 21
     }
22 22
 
23 23
     /**
@@ -25,7 +25,16 @@ public class StringArrayUtils {
25 25
      * @return last element in specified array
26 26
      */ // TODO
27 27
     public static String getLastElement(String[] array) {
28
-        return null;
28
+        //String[] array = {"brown", "fox", "jumps", "over", "the", "lazy", "dog"};
29
+            String word = "";
30
+        for(int i = 0; i < array.length -1; i++){
31
+                
32
+            return word = array[array.length-1];
33
+            
34
+        
35
+    
36
+        }
37
+        return word;
29 38
     }
30 39
 
31 40
     /**
@@ -33,7 +42,12 @@ public class StringArrayUtils {
33 42
      * @return second to last element in specified array
34 43
      */ // TODO
35 44
     public static String getSecondToLastElement(String[] array) {
36
-        return null;
45
+          String word = "";
46
+        for(int i = 0; i < array.length -2; i++){
47
+                
48
+            return word = array[array.length-2];
49
+        }
50
+        return word;
37 51
     }
38 52
 
39 53
     /**
@@ -42,15 +56,29 @@ public class StringArrayUtils {
42 56
      * @return true if the array contains the specified `value`
43 57
      */ // TODO
44 58
     public static boolean contains(String[] array, String value) {
45
-        return false;
59
+        boolean hold = false;
60
+        for(String s:array){
61
+            if(s.equals(value)){
62
+            return hold = true;
63
+            }
64
+        }
65
+        
66
+        return hold;
46 67
     }
47
-
48 68
     /**
49 69
      * @param array of String objects
50 70
      * @return an array with identical contents in reverse order
51 71
      */ // TODO
52 72
     public static String[] reverse(String[] array) {
53
-        return null;
73
+        String [] t = new String [array.length]; 
74
+        for(int i = 0 ;i<array.length;i++){
75
+            t[i] = "";
76
+            for(int j = array[i].length()-1; j>= 0;j--){
77
+                t[i] +=array[i].substring(j,j+1);
78
+            }
79
+        }
80
+    
81
+        return t;
54 82
     }
55 83
 
56 84
     /**
@@ -58,6 +86,13 @@ public class StringArrayUtils {
58 86
      * @return true if the order of the array is the same backwards and forwards
59 87
      */ // TODO
60 88
     public static boolean isPalindromic(String[] array) {
89
+        String length = array.length;
90
+        
91
+        for(int i = 0;i<length;i++){
92
+            String start = array[0];
93
+            String end = array[length];
94
+        }
95
+        
61 96
         return false;
62 97
     }
63 98
 

+ 42
- 0
package.bluej 查看文件

@@ -0,0 +1,42 @@
1
+#BlueJ package file
2
+dependency1.from=StringArrayUtilsTest
3
+dependency1.to=StringArrayUtils
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=685
6
+editor.fx.0.width=1199
7
+editor.fx.0.x=50
8
+editor.fx.0.y=27
9
+objectbench.height=102
10
+objectbench.width=461
11
+package.divider.horizontal=0.6
12
+package.divider.vertical=0.7988929889298892
13
+package.editor.height=426
14
+package.editor.width=674
15
+package.editor.x=20
16
+package.editor.y=43
17
+package.frame.height=600
18
+package.frame.width=800
19
+package.numDependencies=1
20
+package.numTargets=2
21
+package.showExtends=true
22
+package.showUses=true
23
+project.charset=UTF-8
24
+readme.height=58
25
+readme.name=@README
26
+readme.width=47
27
+readme.x=10
28
+readme.y=10
29
+target1.height=50
30
+target1.name=StringArrayUtilsTest
31
+target1.showInterface=false
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=150
34
+target1.x=130
35
+target1.y=10
36
+target2.height=50
37
+target2.name=StringArrayUtils
38
+target2.showInterface=false
39
+target2.type=ClassTarget
40
+target2.width=120
41
+target2.x=70
42
+target2.y=70