I have a question that is related to changing character in Java
For instance :
this is my string value
Sue sells sea shellS on the seashore!
How to change the capital letter of "S" to small letter and change the small letter of "s" to capital letter. this only change the letter "s" and "S" to uppercase and lowercase not other letter.
I've tried this:
String phrase= new String("Sue sells sea shells on the seashore!");
String r= "";
for(int z=0; z<phrase.length();++z)
{
Character c = phrase.charAt(z);
if(Character.isLowerCase(c))
r += Character.toUpperCase(c);
else if(Character.isUpperCase(c))
r += Character.toLowerCase(c);
else r += c;
}
System.out.println(r);
but the problem is the code changes whole characters not only change letter "s" and "S". so, how to change it?