-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackAround
More file actions
19 lines (18 loc) · 729 Bytes
/
backAround
File metadata and controls
19 lines (18 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//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"
public class backAround {
public static void main(String[] args) {
String output=backAround("cat");
System.out.println(output);
String output1=backAround("Hello");
System.out.println(output1);
String output2=backAround("a");
System.out.println(output2);
}
public static String backAround(String str){
return str.substring(str.length()-1)+str+str.substring(str.length()-1);
}
}