Pangram Program in JavaIn this section, we will discuss what is a pangram string. We will also create a Java program to check the given string is a pangram or not. What is pangram string?The string is called a pangram if it contains all the alphabets from a to z or A to Z, ignoring the case sensitivity. Example of Pangram Strings or SentencesThe following string/ sentences are pangram strings:
Algorithm
Pangram Java ProgramIn order to find the pangram string, there are the following two approaches:
Using Frequency Array
Let's implement the above approach in a Java program. PangramStringExample1.java Output: The given string is a pangram string. Using TraversalIn this approach, first, convert all the letters into lowercase letters. After that, traverse over each character from a to z itself. Check if the given string contains all the letters (a to z), if present, print string id pangram, else print string is not pangram. Let's implement the above approach in a Java program. PangramStringExample2.java Output: Pangram String Let's see another approach. In this approach, we have created a Boolean type array named mark[]. Iterate over all the alphabets presented in the string and mark each visited alphabet. Suppose, a or A is found in the string, marked it at index 0. Similarly, for other alphabets. PangramStringExample3.java Output: Fix problem quickly with galvanized jets is a pangram string. Let's see another logic for the same. PangramStringExample4.java Output: Enter the string: pack my box with five dozen liquor jugs The string is a pangram string. ComplexityTime Complexity: Its time complexity is O(n), where n is the length of the string. Space Complexity: Its space complexity is O(1) because it does not require extra space.
Next TopicTop View of a Binary Tree in Java
|