Implement the following methods Write a method that returns

Implement the following methods:

Write a method that returns true if s has leading or trailing whitespace, false otherwise

   public static boolean needsTrim(String s)

Write a method that swaps the first three and last four characters of s

public static String swap3For4(String s)

Write a method that has one String parameter, and returns true if the first half and last half of the parameter are the same ignoring case, and false otherwise.

public static boolean areHalvesEqual(String s)


Use these methods to rewrite the corresponding parts of the StringPlay program. Test the revised program with the following data: (Note: shown in quotes...the quotes are not part of the string)

\"aaabccc\"

\"aaacaaa\"

\"aaaaAAAA\"

\"aaaabbbb\"

\"Doo wah ditty ditty\"

\" Go ahead, make my day!\"

Solution

1)

public static boolean isBlank(String abc) {
int abcLen;
if (abc == null || (abcLen = abc.length()) == 0) {
return true;
}
for (int i = 0; i < abcLen; i++) {
if ((Character.isWhitespace(abc.charAt(i)) == false)) {
return false;
}
}
return true;
}

2)

public String Swap(String abc)
{
  

if (abc.length() == 0){
return \"\";
}

char starting = abc.charAt(3);
char end = abc.charAt(abc.length() - 4);

abc.replace(starting, end);
abc.replace(end, starting);

return abc;
}

Implement the following methods: Write a method that returns true if s has leading or trailing whitespace, false otherwise public static boolean needsTrim(Strin
Implement the following methods: Write a method that returns true if s has leading or trailing whitespace, false otherwise public static boolean needsTrim(Strin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site