Browse Source

stringUtilities re do

Nuridalia.Hernandez 5 years ago
parent
commit
95b016caad
2 changed files with 27 additions and 32 deletions
  1. BIN
      StringUtilities.class
  2. 27
    32
      StringUtilities.java

BIN
StringUtilities.class View File


+ 27
- 32
StringUtilities.java View File

16
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
16
      * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
17
      */
17
      */
18
     public static String concatenation(String firstSegment, String secondSegment){
18
     public static String concatenation(String firstSegment, String secondSegment){
19
-        return firstSegment + secondSegment ;
19
+        return firstSegment + secondSegment;
20
     }
20
     }
21
 
21
 
22
     /**
22
     /**
25
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
25
      * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
26
      */
26
      */
27
     public static String concatenation(int firstSegment, String secondSegment){
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
      * @return the first 3 characters of `input`
33
      * @return the first 3 characters of `input`
36
      */
34
      */
37
     public static String getPrefix(String input){
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
      */
42
      */
45
     public static String getSuffix(String input){
43
     public static String getSuffix(String input){
46
         return input.substring(input.length() - 3);
44
         return input.substring(input.length() - 3);
45
+       
47
     }
46
     }
48
 
47
 
49
     /**
48
     /**
52
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
51
      * @return the equivalence of two strings, `inputValue` and `comparableValue`
53
      */
52
      */
54
     public static Boolean compareTwoStrings(String inputValue, String comparableValue){
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
      * @return the middle character of `inputValue`
62
      * @return the middle character of `inputValue`
61
      */
63
      */
62
     public static Character getMiddleCharacter(String inputValue){
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
      * @return the first sequence of characters
80
      * @return the first sequence of characters
81
      */
81
      */
82
     public static String getFirstWord(String spaceDelimitedString){
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
      * @return the second word of a string delimited by spaces.
89
      * @return the second word of a string delimited by spaces.
92
      */
90
      */
93
     public static String getSecondWord(String spaceDelimitedString){
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
         return spaceDelimitedString.split(" ")[1];
93
         return spaceDelimitedString.split(" ")[1];
99
     }
94
     }
100
 
95
 
103
      * @return an identical string with characters in reverse order.
98
      * @return an identical string with characters in reverse order.
104
      */
99
      */
105
     public static String reverse(String stringToReverse){
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
 }