123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package QuizWeek1;
-
- public class StringUtilities {
- public Character getMiddleCharacter(String word){
-
- int len= word.length();
- int pos;
- if(len%2 == 0)
- {
- pos=((len/2) -1) ;
-
- }
- else
- {
- pos=len/2;
-
- }
- return word.charAt(pos);
- }
-
-
-
- public String removeCharacter(String value, char charToRemove){
- String r="";
- for(int i=0; i < value.length() ;i++)
- {
- if(value.charAt(i) != charToRemove)
- r=r+ value.charAt(i);
- }
- return r;
- }
-
- public String getLastWord(String value) {
-
- String[] r= value.split(" ");
- String lastWord= r [r.length -1];
-
- return lastWord;
- }
- }
-
|