Write a java program to check string is Panagram or not ?
import java.util.Scanner;
public class PanagramString {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a String : ");
String str = sc.nextLine();
if (str.length() < 26) {
System.out.println("Entered String is not Panagram ");
} else {
boolean re = isPanagram(str);
if (re) {
System.out.println("Entered string is panagram ");
} else
System.out.println("Not a panagram string");
}
}
static boolean isPanagram(String str) {
int count[] = new int[26];
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch >= 65 && ch <= 90) {
count[ch - 65]++;
} else if (ch >= 97 && ch <= 122) {
count[ch - 97]++;
}
}
for (int i = 0; i < count.length; i++) {
if (count[i] == 0) {
return false;
}
}
return true;
}
}
Comments
Post a Comment