fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static boolean isAlphabet(char x) {
  11. return ((x >= 'A' && x <= 'Z') || (x >= 'a' && x <= 'z'));
  12. }
  13.  
  14. static void reverse(char ch[]) {
  15.  
  16. int l = 0;
  17. int startIndex = 0;
  18. int endIndex = 0;
  19. while (l < ch.length - 1) {
  20. if (isAlphabet(ch[l])) {
  21. l++;
  22. } else {
  23. endIndex = l - 1;
  24. while (startIndex < endIndex){
  25. char temp = ch[startIndex];
  26. ch[startIndex] = ch[endIndex];
  27. ch[endIndex] = temp;
  28. endIndex--;
  29. startIndex++;
  30. }
  31. l++;
  32. startIndex = l;
  33. }
  34. }
  35. }
  36.  
  37. public static void main(String[] args) throws java.lang.Exception {
  38. String inputString = "comp!ex, ex.amp!e";
  39. char[] ch = inputString.toCharArray();
  40. reverse(ch);
  41. String reverseString = new String(ch);
  42. System.out.println(reverseString);
  43. }
  44. }
Success #stdin #stdout 0.11s 321600KB
stdin
Standard input is empty
stdout
pmoc!xe, xe.pma!e