Check if string has all the letters of the alphabet

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

        public class Pangram {
        public static boolean isPangram(String test){
            for (char a = 'A'; a <= 'Z'; a++)
                if ((test.indexOf(a) < 0) && (test.indexOf((char)(a + 32)) < 0))
                    return false;
            return true;
        }
    
        public static void main(String[] args){
            System.out.println(isPangram("the quick brown fox jumps over the lazy dog"));//true
            System.out.println(isPangram("the quick brown fox jumped over the lazy dog"));//false, no s
            System.out.println(isPangram("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));//true
            System.out.println(isPangram("ABCDEFGHIJKLMNOPQSTUVWXYZ"));//false, no r
            System.out.println(isPangram("ABCDEFGHIJKL.NOPQRSTUVWXYZ"));//false, no m
            System.out.println(isPangram("ABC.D.E.FGHI*J/KL-M+NO*PQ R\nSTUVWXYZ"));//true
            System.out.println(isPangram(""));//false
            System.out.println(isPangram("Pack my box with five dozen liquor jugs."));//true
        }
    }
    

提交回复
热议问题