Verificar si una frase o texto es un pangrama.
Un pangrama (del griego: παν γραμμα, «todas las letras») o frase holoalfabética es un texto que usa todas las letras posibles del alfabeto de un idioma.
https://es.wikipedia.org/wiki/Pangrama
Esta simple clase contiene cuatro metódos diferentes de verificar si un texto es un pangrama
Espero les sea de utilidad
////////////////////////////////
public class Panagrama {
public static void main(String[] args) {
//String strFrase = "abcdefghijklmnopqrstuvwxyz";
String strFrase = "El cadáver de Wamba, rey godo de España, fue exhumado y trasladado en una caja de zinc que pesó un kilo";
char [] arrFrase = strFrase.toCharArray();
String strAlfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char [] arrAlfabeto = strAlfabeto.toCharArray();
boolean blnTodas = isPanagram2(arrAlfabeto,arrFrase);
System.out.println("La frase : "+ strFrase );
if(blnTodas) System.out.println("Es Pangrama");
else System.out.println("No es Pangrama");
}
public static boolean isPanagram(String strFrase){
//recorro todas las letras del alfabeto
for(int i = 0 ; i < 26 ; i++){
if(!strFrase.toUpperCase().contains(""+(char)(65+i)))
return false;
}
return true;
}
public static boolean isPanagram2(String strFrase){
boolean blnLetra = false;
for(int i = 0 ; i < 26 ; i++){
blnLetra = false;
for(int j=0;j
blnLetra=true;
break;
}
}
if(!blnLetra) return false;
}
return true;
}
public static boolean isPanagram3(String strFrase){
for(int i = 0 ; i < 26 ; i++){
boolean blnLetra = true;
for(int j=0;j
blnLetra = false; ;
break;
}
}
if(blnLetra) return false;
}
return true;
}
public static boolean isPanagram2(char[] arrAlfabeto, char[] arrFrase){
boolean blnLetra;
for(int i = 0 ; i < arrAlfabeto.length; i++){
blnLetra = false;
for(int j=0;j
blnLetra=true;
break;
}
}
if(!blnLetra) return false;
}
return true;
}
}
////////////////////////////////
No hay comentarios:
Publicar un comentario