0

所以我正在做的代码是检查句子是否是一个 pangram。此外,代码将每个字符放入哈希图中。然后检查hashmap里面是否有26个元素

import java.util.HashMap;
import java.util.Map;
public class Pangram {
    Map<Character,Integer> map= new HashMap<Character,Integer>();
    public boolean isPangram(String s) {
        
            
        //Upper Case to Lower Case  
        for( Character t:s.toCharArray()){
            if(Character.isUpperCase(t))
                t= Character.toLowerCase(t);
            if( t>='a'&& t<='z') {
                map.put(t,map.getOrDefault(t, 0)+1);
            }
            return map.keySet().size()== 26;
            
        }
        return false;
    }
    public static void main(String[] args) {
        Pangram eq=new Pangram();
        System.out.println(eq.isPangram("A quick brown fox jumps over the  "));
        System.out.println(eq.isPangram("brown jars prevented the mixture from freezing too quickly"));
        System.out.println(eq.isPangram("Pack my box with five dozen liquor jugs"));
        System.out.println(eq.map);
        
    }
    }*

代码一直返回 false,但发布后返回 true

4

0 回答 0