Computer Science-Java

posted by .

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?

  • Computer Science-Java -

    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

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. programming

    write a program that maintains two parallel arrays. after th arrays have been loaded the program should behave as a login screen prompting for username and password. the program should respond three output messages. if username does …
  2. Computer Sciene-java

    Write a loop that will continuously prompt the user for integers to sum, -1 to exit. Sum these values and display the sum to the console. Here is what I have so far, but I feel like I am missing something: public class Sum1 { public …
  3. Computer Science (MATLAB)

    I had a test in my computer science course in which I was asked if any while loop can be replaced with a for loop. I put true. I guess the answer was false. My professor said that if you had a while loop in which you asked the user …
  4. Computer Science (MATLAB)

    I had a test in my computer science course in which I was asked if any while loop can be replaced with a for loop. I put true. I guess the answer was false. My professor said that if you had a while loop in which you asked the user …
  5. computer science

    hi i am using java to make a quiz... i am using JFrame and have radio buttons so the user can give his answer. For example: Who co-stared with Leonardo Dicaprio in the movie Titanic?
  6. java

    Write a java application that finds the smallest of several integers. Prompt the user for the number of integers that will be input, then prompt the user for that number of integers. Evaluate the integers to determine the smallest …
  7. Java

    in Java how do you create a method that will prompt the user to type in 10 votes to determine a winner in a two candidate election?
  8. java.please help

    Write a Java program that prompts the user for a string. If the string entered by the user does not start with Hello and does not end with a digit, print incorrect and re-prompt the user. Otherwise, print Thank you.
  9. java programming

    the learner is asked to write a program using java with user input that caculate and displays, the number of months it will take the user to save an amount of money. the user must enter the
  10. computer, science, java, software

    Write a Java program to declare and store numbers from 1 to 10 in a single dimensional array and display the output in the following format. 1 2 3 4 5 6 7 8 9 10

More Similar Questions