A pangram is a word or sentence that contains every letter of the alphabet. For
ID: 3841118 • Letter: A
Question
A pangram is a word or sentence that contains every letter of the alphabet. For example the quick brown fox jumps over the lazy dog. Nicole wants to improve her typing speed for programming contests, and she thinks that practicing typing pangrams is the best way to do it. Given N strings comprised of lowercase letters (a Z) and spaces, determine whether or not they are pangrams. Complete the isPangram function, which takes an array of N strings (Sa S SN.1) as a parameter and returns a string of N binary characters. Each character i of the returned string should be a 1 if string S is a pangram or e if it is not. Input Format The locked code in your editor assembles the following input and passes it to the isPangram function: The first line contains an integer the number of strings. Each line i (where 0 siExplanation / Answer
#import java.io.*;
#import java.util.Scanner
pulic class Solution {
public static String isPangram(String[] strings){
int array[26] //holds the presence of a character as 1 and absence as 0
String ans;
String data;
ans = ""; //The binary string which will be returned after processing of all the strings
for (int i = 0; i<strings.length; i++){
for (int k = 0; k<26; k++){ // Initialize the array.first array location corresponds to presence of a. If a
// is present, its value is 1 otherwise 0. Similarly a[1] for b ...a[2] for c..
array[k] = 0;
}
data = strings[i];
data.toLowerCase(); // Converted the string to lowercase
for (j=0; j<data.length(); j++){
if (data.charAt(j) >= 'a' && data.charAt(j) <= 'z')
array[data.charAt(j)-97] = 1;
}
found = 1; // holds whether a string is a pangram or not. Assume it is a pangram
for (int k = 0; k<26; k++){
if (array[k] == 0){
found = 0;
break;
}
}
if (found == 1)
ans = ans + "1";
else
ans = ans + "0";
}
return ans;
}
public static void main(String[] args) throws IOException {
int n, i;
String [] strings;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of strings:");
n = sc.nextInt();
strings = new String[n];
for (i = 0; i<n; i++){
System.out.println("Enter " + i + "String:");
string[i] = sc.nextLine();
}
System.out.println( IsPangram(strings));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.