ソースを参照

stringUtilities re do

コミット
95b016caad
共有2 個のファイルを変更した27 個の追加32 個の削除を含む
  1. バイナリ
      StringUtilities.class
  2. 27
    32
      StringUtilities.java

バイナリ
StringUtilities.class ファイルの表示


+ 27
- 32
StringUtilities.java ファイルの表示

@@ -16,7 +16,7 @@ public class StringUtilities {
16 16
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
17 17
      */
18 18
     public static String concatenation(String firstSegment, String secondSegment){
19
-        return firstSegment + secondSegment ;
19
+        return firstSegment + secondSegment;
20 20
     }
21 21
 
22 22
     /**
@@ -25,9 +25,7 @@ public class StringUtilities {
25 25
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
26 26
      */
27 27
     public static String concatenation(int firstSegment, String secondSegment){
28
-        String n = Integer.toString(firstSegment);
29
-        return n + secondSegment;
30
-
28
+        return firstSegment  + secondSegment;
31 29
     }
32 30
 
33 31
     /**
@@ -35,7 +33,7 @@ public class StringUtilities {
35 33
      * @return the first 3 characters of `input`
36 34
      */
37 35
     public static String getPrefix(String input){
38
-        return input.substring(0, 3);
36
+        return input.substring(0,3);
39 37
     }
40 38
 
41 39
     /**
@@ -44,6 +42,7 @@ public class StringUtilities {
44 42
      */
45 43
     public static String getSuffix(String input){
46 44
         return input.substring(input.length() - 3);
45
+       
47 46
     }
48 47
 
49 48
     /**
@@ -52,7 +51,10 @@ public class StringUtilities {
52 51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
53 52
      */
54 53
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
55
-        return inputValue.equals(comparableValue) ;
54
+        if (inputValue.equals(comparableValue)){
55
+                return true;}
56
+        
57
+        return false;
56 58
     }
57 59
 
58 60
     /**
@@ -60,19 +62,17 @@ public class StringUtilities {
60 62
      * @return the middle character of `inputValue`
61 63
      */
62 64
     public static Character getMiddleCharacter(String inputValue){
63
-        int post;
64
-        int leng;
65
-        if (inputValue.length()% 2 == 1){
66
-            post=inputValue.length()/2;
67
-            leng= 1;
68
-        } else {
69
-            post=inputValue.length()/2-1;
70
-            leng = 2; 
71
-        }
72
-        String mid = inputValue.substring(post, post
73
-                + leng);
74
-                char output = mid.charAt(0);
75
-        return output;//inputValue.charAt(inputValue.length()/2);
65
+        int remeinder = 0;
66
+        int leng = inputValue.length();
67
+        if ( inputValue.length() % 2 == 0) {
68
+            remeinder = leng /2 -1;
69
+             
70
+        } else { remeinder = leng /2 ; }
71
+        
72
+        
73
+               
74
+        return inputValue.charAt(remeinder);
75
+        
76 76
     }
77 77
 
78 78
     /**
@@ -80,10 +80,8 @@ public class StringUtilities {
80 80
      * @return the first sequence of characters
81 81
      */
82 82
     public static String getFirstWord(String spaceDelimitedString){
83
-        int str= spaceDelimitedString.indexOf(" ");
84
-        String word = spaceDelimitedString.substring(0, str);
85
-
86
-        return word ;
83
+        
84
+        return spaceDelimitedString.split(" ")[0];
87 85
     }
88 86
 
89 87
     /**
@@ -91,10 +89,7 @@ public class StringUtilities {
91 89
      * @return the second word of a string delimited by spaces.
92 90
      */
93 91
     public static String getSecondWord(String spaceDelimitedString){
94
-        /**int word = spaceDelimitedString.indexOf(" ");
95
-        int word1 = spaceDelimitedString.indexOf("", word );
96
-        String secondWord=spaceDelimitedString.substring(word , word1);
97
-        return secondWord;*/
92
+       
98 93
         return spaceDelimitedString.split(" ")[1];
99 94
     }
100 95
 
@@ -103,11 +98,11 @@ public class StringUtilities {
103 98
      * @return an identical string with characters in reverse order.
104 99
      */
105 100
     public static String reverse(String stringToReverse){
106
-        String reverse="";
107
-        for(int i = stringToReverse.length() - 1; i >= 0; i--)
108
-        {
109
-            reverse = reverse+ stringToReverse.charAt(i);
101
+        String temp = "";
102
+        for(int i = stringToReverse.length () - 1; i >=0; i--){
103
+            temp += stringToReverse.charAt (i); 
110 104
         }
111
-        return reverse;
105
+        
106
+        return temp ;
112 107
     }
113 108
 }