I wanted to create a method that reverse upper-lower case letters in a word. The problem I'm having is that the method doesn't reverse all the letters. For example when I type "nIceToMeEtyoU" it prints "NiCETomEETYou". It didn't work for the "o", the second "e" and "t". I just couldn't figure out what's wrong with the code.
public static String reverseCase(String str) {
char changed;
String a = str;
for (int i = 0; i < a.length(); i++) {
char d = a.charAt(i);
boolean letter = Character.isUpperCase(d);
if (letter == true) {
changed = Character.toLowerCase(d);
} else {
changed = Character.toUpperCase(d);
}
a = a.replace(d, changed);
}
return a;
}