with Java Pangrams A pangram is a word or sentence that contains every letter of
ID: 3841665 • Letter: W
Question
with Java
Pangrams 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 Si is a pangram or 0 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 N, the number of strings. Each line i (where 0 siExplanation / Answer
//just put this method in your program and call it with the parameter array of string and it return the string with //binary character I also test all the strings you provided in the Question, it is working properly
static String isPanagram(String[] strings)
{
String res=""; //string that return binary Character
if(strings.length<1) //just in case if no string in array "you mentioned just before the program //that 'no string in array is a panagram' so return 1"
{
return "1";
}
for(int i=0;i<strings.length;i++)
{
String firstString = strings[i];
firstString = firstString.toLowerCase();
int length = firstString.length();
if(length<26) //its so obvious if the string length is less than 26 than it can't be a //panagram string
res=res+"0";
else
{
char c;
for(c = 'a'; c <= 'z' ; c++) //loop from a to z with a character 'c' just a character variable for loop
{
if((firstString.indexOf(c) < 0) && (firstString.indexOf((char)(c + 32)) < 0))
{
res=res+"0"; //if we do not find the charcter in string than "indexOf" return -1 and
//we set a charcter in string res '0' and break the loop
break;
}
}
if(c>'z') //if the value of variable 'c' is greater than 'z' than it means that the loop executed //full without break that mean all the
//alphabets are avilable in the string so,set 1 in string res
res=res+"1";
}
}
System.out.println(res);
return res;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.