SHARE
TWEET

hcj

a guest Jul 21st, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MainActivity extends AppCompatActivity {
  2.     EditText inputString;
  3.     Button getResult;
  4.     TextView result;
  5.     String strForManipulation;
  6.     String reversedString;
  7.  
  8.     @Override
  9.     protected void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         setContentView(R.layout.activity_main);
  12.  
  13.         inputString = findViewById(R.id.input_string_et);
  14.         getResult = findViewById(R.id.get_result_bt);
  15.         result = findViewById(R.id.show_result_tv);
  16.  
  17.  
  18.         getResult.setOnClickListener(new View.OnClickListener() {
  19.             @Override
  20.             public void onClick(View v) {
  21.                 strForManipulation = inputString.getText().toString();
  22.                 reversedString = Anagram.mainReverseMethod(strForManipulation);
  23.                 result.setText(reversedString);
  24.  
  25.             }
  26.         });
  27.     }
  28.  
  29.  
  30.  
  31.  
  32.  
  33. public class Anagram {
  34.     private static final String SEPARATOR = " ";
  35.  
  36.     public static String mainReverseMethod(String strForManipulation) {
  37.         String check = "";
  38.         int leftCounter = 0;
  39.  
  40.  
  41.         StringBuilder string = new StringBuilder();
  42.         StringBuilder stringBuilder = new StringBuilder();
  43.         String[] splitString = strForManipulation.split(SEPARATOR);
  44.         for (String word : splitString) {
  45.             char[] everySymbol = word.toCharArray();
  46.             int rightCounter = everySymbol.length - 1;
  47.  
  48.             while (leftCounter < rightCounter) {
  49.                 if (!Character.isLetter(everySymbol[leftCounter]))
  50.                     leftCounter++;
  51.                 else if (!Character.isLetter(everySymbol[rightCounter]))
  52.                     rightCounter--;
  53.  
  54.                 else {
  55.                     char tmp = everySymbol[leftCounter];
  56.                     everySymbol[leftCounter] = everySymbol[rightCounter];
  57.                     everySymbol[rightCounter] = tmp;
  58.                     leftCounter++;
  59.                     rightCounter--;
  60.                 }
  61.  
  62.             }
  63.             stringBuilder.append(everySymbol).append(SEPARATOR);
  64.  
  65.             check = stringBuilder.toString();
  66. //
  67.  
  68.         }
  69.         return check;
  70.     }
  71.  
  72.  
  73. }
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