Created
May 3, 2018 18:07
-
-
Save sumitsingh6/11334c764a9e533ded5063e53f8e4602 to your computer and use it in GitHub Desktop.
Given a string, return a new string where the first and last chars have been exchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Given a string, return a new string where the first and last chars have been exchanged. | |
| public String frontBack(String str) { | |
| int n=str.length(); | |
| if(n>=2){ | |
| return str.substring(n-1)+str.substring(1,n-1)+str.substring(0,1); | |
| } | |
| else | |
| return str; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment