Check if string has all the letters of the alphabet

前端 未结 15 1142
终归单人心
终归单人心 2020-12-19 17:51

What would be the best logic to check all the letters in a given string.

If all the 26 letters are available in the provided string, I want to check that and perform

15条回答
  •  有刺的猬
    2020-12-19 18:27

    public static void main(String[] args) {
    
        String A ="asdfsdafasdf";
        String B ="abcdefghijklmnopqrstuvwxyz";
        String C ="ASDFGFHWER";
        String result = "NO";
    
        String letters[] = {A,B,C};
        int length = letters.length;
    
        for(int j=0; j< length; j++){
            String letter = letters[j].toLowerCase();
            int letterLength = letter.length();
            for(char i='a'; i<'z'+1; i++){
                if(letter.contains (""+i)){
                    result ="YES";
                } else{
                    result = "NO";
                }
            }
            System.out.println(result);
        }
    }
    

提交回复
热议问题