-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBackAround.java
More file actions
21 lines (17 loc) · 650 Bytes
/
BackAround.java
File metadata and controls
21 lines (17 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*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 {
//Class for testing and setting dummy values
public static void main( String [] args ) {
//Output tests
System.out.println( backAround( "Hello" ) );
}
public static String backAround( String str ) {
int length = str.length();
char lastLetter = str.charAt( length - 1 );
return lastLetter + str + lastLetter;
}
}