Browse Source

completed few methods

Yesoda Sanka 6 years ago
parent
commit
96b294f1a2
1 changed files with 20 additions and 37 deletions
  1. 20
    37
      StringUtilities.java

+ 20
- 37
StringUtilities.java View File

@@ -1,42 +1,25 @@
1
- //import java.utils.*;
1
+//import java.utils.*;
2 2
 public class StringUtilities {
3
-   public Character getMiddleCharacter(String word){
4
-       int  n= word.length();
5
-       char ch;
6
-       int val=n%2;
7
-       int i=0;
8
-       if(val== 0)
9
-       {  
10
-          i =n/2;
11
-          ch=word.charAt(i);
12
-           //System.out.println(val);
13
-           return ch;
14
-          
15
-        }
16
-          else
17
-          {
18
-          i=(int)Math.floor(n/2);
19
-          ch= word.charAt(i -1);
20
-          return ch;
21
-        }
22
-    }    
23
-       
24
-   
3
+    public Character getMiddleCharacter(String word){
4
+        return word.charAt(word.length()/2);
25 5
 
6
+    }
26 7
    
27
-   public String removeCharacter(String value, char charToRemove){
28
-       int n=value.length();
29
-       for(int i=0;i<n;i++)
30
-       {
31
-           
32
-        }
33
-       
34
-    
35
-    
36
-   return null;
37
-}
38 8
    
39
-   public String getLastWord(String value) {
40
-       return null;
41
-   }
9
+    public String removeCharacter(String value, char charToRemove){
10
+        String s="";
11
+        s=s+charToRemove;
12
+        String str="";
13
+        str =str+value.replace(s,"");       
14
+
15
+        return str;
16
+    }
17
+
18
+    public String getLastWord(String value) {
19
+        //int n=value.length();
20
+        String str=value.substring(value.lastIndexOf(" ")+1);
21
+
22
+        return str;
23
+    }
24
+
42 25
 }