SHARE
TWEET

Reverse

a guest Jul 16th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  public static String mainReverseMethod(String strForManipulation) {
  2.  
  3.  
  4.         StringBuilder string = new StringBuilder();
  5.         String check = "";
  6.         String[] splitString = strForManipulation.split(SEPARATOR);
  7.         for (String word : splitString) {
  8.             char[] everySymbol = word.toCharArray();
  9.             reverse(everySymbol);
  10.             string.append(SEPARATOR);
  11.             check = string.append(everySymbol).toString();
  12.         }
  13.         return check;
  14.     }
  15.  
  16.     private static String reverse(char[]everySymbol) {
  17.         StringBuilder stringBuilder = new StringBuilder();
  18.  
  19.         int leftCounter = 0;
  20.         int rightCounter = everySymbol.length - 1;
  21.  
  22.  
  23.  
  24.         while (leftCounter < rightCounter) {
  25.             if (!Character.isLetter(everySymbol[leftCounter]))
  26.                 leftCounter++;
  27.             else if (!Character.isLetter(everySymbol[rightCounter]))
  28.                 rightCounter--;
  29.  
  30.             else {
  31.                 char tmp = everySymbol[leftCounter];
  32.                 everySymbol[leftCounter] = everySymbol[rightCounter];
  33.                 everySymbol[rightCounter] = tmp;
  34.                 leftCounter++;
  35.                 rightCounter--;
  36.             }
  37.  
  38.         }
  39.  
  40.         return stringBuilder.append(everySymbol).toString() ;
  41.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top