for loop to find consonants in a string

后端 未结 5 1028
灰色年华
灰色年华 2021-01-28 02:24

Using a for loop, how do I go about making all consonants in a string uppercase?

I think I should do something like this:

    String str = \"fish$\"             


        
5条回答
  •  温柔的废话
    2021-01-28 02:36

    String str = "fish$";   
    String strVowels = "aeiouAEIOU";
    String out = "";
    
    for (Character c : str.toCharArray()) 
    {
        if(!strVowels.contains(""+c))
        {
            out = out + Character.toUpperCase(c);
        }
        else
        {
            out = out + c;
        }
    }
    System.out.println(out);
    

提交回复
热议问题