Created
February 6, 2017 22:42
-
-
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
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
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"This is SaM!" changes to "sihT is SaM!"