Using the bufferedReader, how can you check if a line contains a letter or a number?
I just thought of this at the top of my head:
readLine().matches("[A-Za-z0-9 ]+")
Would you recommend this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Read the line as a String from the buffered reader, then iterate through the chars of the String, and use
Character.isLetter(char)andCharacter.isDigit(char)to know if the current char is a letter or a digit.All the methods of all the classes are described in the javadoc.
The call to matches will return true only if the line contains only the characters specified by the regex. You’ll need to use a Matcher and call find to detect if the STring contains one of the chars in
[A-Za-z0-9 ].Note that your pattern contains a space, which is not a letter nor a digit. Also note that there are a whole loat of letters which are not in
[A-Za-z].