I'm trying to write a program that changes the case of two characters in a string (change uppercase to lowercase and vice versa).It compiled, but the string is the same.
String newChar1 = caseChanger("DcoderIsCool", 3);
String newChar2 = caseChanger("DcoderIsCool", 8);
I think the problem is with the method i used:
public static String caseChanger (String s, int ind) {
if(!(Character.isUpperCase(s.charAt(ind)))) {
//checking if the character is uppercase or lowercase
return s.substring(ind, ind + 1).toLowerCase();
} else {
return s.substring(ind, ind + 1).toUpperCase();
}
}
The output should have been "DcoDerIscool", but it's "DcoderIsCool" (the original string).