This is a problem mentioned on Hackerrank. Below is my attempt to solve this problem.
Problem Statement
Problem Statement
Roy
wanted to increase his typing speed for programming contests. So, his
friend advised him to type the sentence "The quick brown fox jumps over
the lazy dog" repeatedly because it is a pangram. ( pangrams are
sentences constructed by using every letter of the alphabet at least
once. )
After typing the sentence several times, Roy became bored with it. So he started to look for other pangrams.
Given a sentences , tell Roy if it is a pangram or not.
After typing the sentence several times, Roy became bored with it. So he started to look for other pangrams.
Given a sentence
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
char[] str = in.nextLine().toCharArray();
boolean[] resultArr = new boolean[26];
int smallMax = 'z';
int capMax = 'Z';
for (int i = 0; i < str.length; i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
resultArr['z' - str[i]] = true;
} else if (str[i] >= 'A' && str[i] <= 'Z') {
resultArr['Z' - str[i]] = true;
}
}
boolean flag = true;
for (int j = 0; j < resultArr.length; j++) {
if (resultArr[j] == false) {
flag= false;
break;
}
}
if(flag == true){
System.out.println("pangram");
}else{
System.out.println("not pangram");
}
}
}
Nice informative post! Thanks for sharing the code. Here is my blog where I share valuable information like this too. Learn the Touch typing technique and make your typing fast.
ReplyDelete