So if I were to have the string
String str = " mommy ";
How would I get the output
"MoMMy"
So if I were to have the string
String str = " mommy ";
How would I get the output
"MoMMy"
To get the desired output , you can follow the following code
String str = "mommy";
char [] str1 = str.toCharArray();
for(int i = 0; i < str.length(); i++){
if(str1[i] == 'm'){
str1[i] = 'M';
}
}
String str2 = new String(str1);
System.out.println(str2);