Web Analytics Made Easy -
StatCounter User Input question - CodingForum


No announcement yet.

User Input question

  • Filter
  • Time
  • Show
Clear All
new posts

  • User Input question

    I am writing a method that asks a user for information via a Dialog request box which works fine.

    It basically says "Please input product name or * to close");

    This is part of a while loop that as long as I keep entering products the request box will reappear.

    Then adds the inputted product name to a set which also works fine, but how would I write it that so if the * is entered it breaks the loop ?

    Im using this but the bit to exit doesn't work. Anyone got an idea ??

    [COLOR="Red"]String exit = "*";
    String myInput = NWUDialog.request("Please input product name or * to close");
           while(myInput != null && myInput != exit)[/COLOR]
    Then it goes into the loop here

  • #2
    You will need to adjust how you check for the exit condition. When comparing Strings, you cannot use the == or != comparison, instead you need to use the equals method of the String class. Here is an example:
    PHP Code:
    String s1 "test";
    String s2 "test";
    String s3 "not test";

    s1.equals(s2); //returns true
    s1.equals(s3); //returns false 


    • #3
      while(myInput != null && !myInput.equals("*")) will work.
      [Java Servlet tutorials] [Tomcat tutorials] [Ask a java question]