Check if string has all the letters of the alphabet

前端 未结 15 1321
终归单人心
终归单人心 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:30

    Try this one out it's easy and simple to understand

    import java.util.*;
    
    public class Pnagram{
        public static void main(String[] args){
            Scanner sc=new Scanner(System.in);
            String Str=sc.nextLine();
            Set set = new HashSet();
    
            for(char c:Str.toUpperCase().toCharArray()){
                if(Character.isLetter(c))
                set.add(c);
            }
            if(set.size()==26)
                System.out.println("pnagram");
            else
                System.out.println("not pnagram");
        }
    }
    

提交回复
热议问题