Skip to content

Instantly share code, notes, and snippets.

@shailrshah
Created February 6, 2017 22:42
Show Gist options
  • Select an option

  • Save shailrshah/deaf3325ad51af80ac2fc9b56a0f984a to your computer and use it in GitHub Desktop.

Select an option

Save shailrshah/deaf3325ad51af80ac2fc9b56a0f984a to your computer and use it in GitHub Desktop.
Reversing each alphabet of the words, Keeping the order of the words and whitespaces intact
import java.util.Scanner;
class InPlaceRev{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
StringBuilder sbAns = new StringBuilder();
int i = 0;
while(i < str.length()){
StringBuilder sbRev = new StringBuilder();
while(i < str.length() && Character.isLetter(str.charAt(i))){
sbRev.append(str.charAt(i));
i++;
}
sbAns.append(sbRev.reverse());
while(i < str.length()){
sbAns.append(str.charAt(i));
i++;
}
}
System.out.println(sbAns);
}
}
@shailrshah
Copy link
Copy Markdown
Author

"This is SaM!" changes to "sihT is SaM!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment