Guest User

Swap letters problem

a guest
Apr 20th, 2022
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. String[] word = new String[normalWord.length()];
  2. String answer = "";
  3.  
  4. for (int i = 0; i < normalWord.length(); i++) {
  5. if (i != normalWord.length() - 1)
  6. word[i] = normalWord.substring(i, i+1);
  7. else
  8. word[i] = normalWord.substring(i);
  9. }
  10.  
  11. for (int j = 0; j < word.length; j += 2) {
  12. if (j != word.length - 1 ) {
  13. if (word[j].compareToIgnoreCase("A") == 0 && word[j + 1].compareToIgnoreCase("A") != 0) {
  14. String temp = word[j];
  15. word[j] = word[j+1];
  16. word[j + 1] = temp;
  17. }
  18. }
  19. else
  20. word[j] = word[j];
  21. }
  22.  
  23. for (int z = 0; z < word.length; z++) {
  24. answer += word[z];
  25. }
  26.  
  27.  
  28. System.out.println(answer);
Advertisement
Add Comment
Please, Sign In to add comment