Asked by Lisa
                Hi,
I have to prompt a user to input a password and have to verify whether or not it is a single word. How would I do something like?
            
        I have to prompt a user to input a password and have to verify whether or not it is a single word. How would I do something like?
Answers
                    Answered by
            MathMate
            
    You would read the password and store it as as String.  Then there are many ways to check if it is a single word.  
You need to know what the separators of words are. Most of the time we think of spaces, but there are tabs, punctuation marks, parentheses, etc.
If it is a single character (space) you can use the string function indexOf(String, character) to see if it returns a non negative number.
If it is a collection of different characters, you may think of using the string function matches(regexp) which allows you to specify many characters at the same time.
If you read up the String class of the Java API, you will find a lot of possibilities.
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
There is even a video on Strings on UTube (I have not perused it):
http://www.youtube.com/watch?v=tU67suVZVfQ
    
You need to know what the separators of words are. Most of the time we think of spaces, but there are tabs, punctuation marks, parentheses, etc.
If it is a single character (space) you can use the string function indexOf(String, character) to see if it returns a non negative number.
If it is a collection of different characters, you may think of using the string function matches(regexp) which allows you to specify many characters at the same time.
If you read up the String class of the Java API, you will find a lot of possibilities.
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
There is even a video on Strings on UTube (I have not perused it):
http://www.youtube.com/watch?v=tU67suVZVfQ
                                                    There are no AI answers yet. The ability to request AI answers is coming soon!
                                            
                Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.