Created
February 26, 2020 18:03
-
-
Save parzibyte/8234c2438af4e1c2c4f28e033261dad1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
____ _____ _ _ _ | |
| _ \ | __ \ (_) | | | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___ | |
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \ | |
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/ | |
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___| | |
__/ | __/ | | |
|___/ |___/ | |
Blog: https://parzibyte.me/blog | |
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/ | |
Contacto: https://parzibyte.me/blog/contacto/ | |
Copyright (c) 2020 Luis Cabrera Benito | |
Licenciado bajo la licencia MIT | |
El texto de arriba debe ser incluido en cualquier redistribucion | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
String cadenas[] = { "Parzibyte", "parzibyte.me", "123", "H0la", "Hola mundo", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }; | |
for (String cadena : cadenas) { | |
System.out.printf("Probando con '%s'. Resultado: %b\n", cadena, contieneSoloLetras(cadena)); | |
} | |
} | |
public static boolean contieneSoloLetras(String cadena) { | |
for (int x = 0; x < cadena.length(); x++) { | |
char c = cadena.charAt(x); | |
// Si no está entre a y z, ni entre A y Z, ni es un espacio | |
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ')) { | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment