Results 1 to 5 of 5
  1. #1
    JoePenguin is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default can you define an if statement by a keyword entered by the user?

    i would like to know if it is possible and how to create an if statement around a keyword entered by the user so that if the user says enters a word in the input (even if its in a sentence), the if statement will respond.

    this means if i wanted the if statement to respond to the word "fox", it would respond wether it was just the user typing "fox" or if the user types "i saw a fox".

    i know the basics like if statements and useing user input and stuff, its just the keywords thing im after

    thanks guys :D

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: can you define an if statement by a keyword entered by the user?

    this means if i wanted the if statement to respond to the word "fox", it would respond wether it was just the user typing "fox" or if the user types "i saw a fox".
    Check the String method indexOf(). This will help you determine whether the string "fox" occurs anywhere in the user's input.

    If you want "fox" to appear as a word - ie surrounded by white space, punctuation or the ends of the string - the problem becomes more complex.

  3. #3
    JoePenguin is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: can you define an if statement by a keyword entered by the user?

    Check the String method indexOf(). This will help you determine whether the string "fox" occurs anywhere in the user's input.
    you my friend, are amazing <3

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: can you define an if statement by a keyword entered by the user?

    You're welcome.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,432
    Rep Power
    18

    Default Re: can you define an if statement by a keyword entered by the user?

    I'll see your indexOf() and raise you a contains()...;)

Similar Threads

  1. how to append data entered by user to XML file in proper format using JSP
    By gurpreet.singh in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 03-09-2011, 11:22 AM
  2. Replies: 5
    Last Post: 11-22-2010, 07:33 PM
  3. Boggle game - verify words entered by user
    By dragonwolf in forum New To Java
    Replies: 11
    Last Post: 11-30-2009, 04:18 AM
  4. Can't get my "if" statement to read user input
    By daletron3030 in forum New To Java
    Replies: 7
    Last Post: 01-16-2009, 05:24 AM
  5. calendar of 12months when year is entered
    By veena in forum New To Java
    Replies: 16
    Last Post: 05-06-2008, 05:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •