for loop to find consonants in a string

后端 未结 5 1031
灰色年华
灰色年华 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:33

    use String.contains() method from String API. the followingcode would work for your present input. usually, if you want to find all the consonents, have an char[] of consonents or String with all the consonents and do the check.

    String str = "fish$";     
    String strConsonants = "f, s, h"; 
    String temp="";
    for (int x = 0; x < str.length(); x++){
    temp+= str.charAt(x);   
       if(!strConsonants.contains(temp)) {
        consonentsUCase+=temp.toUpperCase();
       }
       temp="";
    }
    

提交回复
热议问题