I'm starting to learn to use Java.
I'm stuck on a problem in codingbat (http://codingbat.com/prob/p123384): here is my code
public String frontBack(String str) {
if (str.length() > 1)
{
char first = str.charAt(0);
char last = str.charAt(str.length()-1);
String middle = str.substring(1,(str.length()-1));
return last + first + middle;
}
else
return str;
}
And here is the output:
(I can't put an image as I'm a new user)
Expected: Run:
frontBack("code") → "eodc" "200od" X
frontBack("a") → "a" "a" OK
frontBack("ab") → "ba" "195" X
frontBack("abc") → "cba" "196b" X
frontBack("") → "" "" OK
frontBack("Chocolate") → "ehocolatC" "168hocolat" X
frontBack("aavJ") → "Java" "171av" X
frontBack("hello") → "oellh" "215ell" X
Why do I get all these fancy numbers? My solution is fairly similar to the solution provided by codingbat...