1234567891011121314151617181920212223242526272829303132 |
- public class StringUtilities {
- public Character getMiddleCharacter(String word){
- if (word.length() % 2 != 0) {int length = word.length() - 1;
- int middle = length / 2;
- String math = String.valueOf(middle + 1);
- int halfway = Integer.valueOf(math);
- String thechar = word.substring(halfway - 1, halfway);
- char itsthechar = thechar.charAt(0);
- return itsthechar;} else {
-
- int length = word.length();
- int middle = length / 2;
- String math = String.valueOf(middle + 1);
- int halfway = Integer.valueOf(math);
- String thechar = word.substring(halfway - 1, halfway);
- char itsthechar = thechar.charAt(0);
- return itsthechar;
- }}
-
- public String removeCharacter(String value, char charToRemove){
- String thechar = String.valueOf(charToRemove);
- String format = value.replaceAll(thechar,"");
- return format;
- }
-
- public String getLastWord(String value) {
- String[] splitem = value.split("\\s+");
- int length = splitem.length;
- return splitem[length-1];
- }
- }
|