Last active
August 29, 2015 14:06
-
-
Save amastov/74611aadf7daacb20c39 to your computer and use it in GitHub Desktop.
check letters
This file contains hidden or 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
Scanner in = new Scanner(System.in); | |
String input = ""; | |
int nonLetters; | |
boolean hasNonLetters = false; | |
while(!hasNonLetters) { | |
nonLetters = 0; | |
System.out.println("Please enter a valid input"); | |
input = in.next(); | |
for (int i = 0; i < input.length(); i++) { | |
//You should check out the ascii table here: https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html | |
//to see exactly what you want to check for. The logic that checks the value is in the if statement below. | |
//that "(int)" part casts the input character to an integer and that integer is the ascii value. | |
if ((int) input.charAt(i) < 64) { | |
nonLetters++; | |
} | |
} | |
if (!(nonLetters > 0)) { | |
hasNonLetters = true; | |
} | |
} | |
.--. | |
`. \ | |
\ \ | |
. \ | |
: . | |
| . | |
| : | |
| | | |
..._ ___ | | | |
`."".`''''""--..___ | | | |
,-\ \ ""-...__ _____________/ | | |
/ ` " ' `"""""""" . | |
\ L | |
(> \ | |
/ \ | |
\_ ___..---. L | |
`--' '. \ | |
. \_ | |
_/`. `.._ | |
.' -. `. | |
/ __.-Y /''''''-...___,...--------.._ | | |
/ _." | / ' . \ '---..._ | | |
/ / / / _,. ' ,/ | | | |
\_,' _.' / /'' _,-' _| | | |
' / `-----'' / | | |
`...-' `...-' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment