Skip to content

Instantly share code, notes, and snippets.

@sumitsingh6
Created May 3, 2018 18:07
Show Gist options
  • Select an option

  • Save sumitsingh6/11334c764a9e533ded5063e53f8e4602 to your computer and use it in GitHub Desktop.

Select an option

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.
//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