Skip to content

Instantly share code, notes, and snippets.

@amastov
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amastov/74611aadf7daacb20c39 to your computer and use it in GitHub Desktop.
Save amastov/74611aadf7daacb20c39 to your computer and use it in GitHub Desktop.
check letters
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