Java > Warmup-1 > backAround (CodingBat Solution)

Problem:

Given a string, take the last char and return a new string with the last char added at the front and back, so "cat" yields "tcatt". The original string will be length 1 or more.

backAround("cat") → "tcatt"
backAround("Hello") → "oHelloo"
backAround("a") → "aaa"


Solution:

public String backAround(String str) {
  char temp = str.charAt(str.length() - 1);
  return temp + str + temp;
}


1 comment :

  1. return str.charAt(str.length()-1)+str+ str.charAt(str.length()-1);

    ReplyDelete

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact