-3

So if I were to have the string

String str = " mommy ";

How would I get the output

"MoMMy" 
azro
  • 53,056
  • 7
  • 34
  • 70

1 Answers1

0

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);