Results 1 to 3 of 3
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default Problems with while loop

    Hello, I am currently trying to write a new program which enters a while loop waiting for s,g,l to be entered to e to exit the loop.

    i have been trying to with no luck.

    Any help of where to start what to declare, programming need.Using methods if that help

    thanks!

    Albert:rolleyes:

  2. #2
    Daniel is offline Member
    Join Date
    Jun 2007
    Posts
    91
    Rep Power
    0

    Default

    Well, what have you written so far? Do you need a full on tutorial or do you just need help in the while loop area?

    Sun provides a great tutorial on java here:

    To which they talk about while loops here:
    While Loop

    And talk about String Equals here:
    String Comparison

    We aren't going to do your assignment for you (as per the rules), but if you write something we can help you along the way.

    And if you're not beginning just look a tthe while loop and String Equals part. That should help the most.

    Greetings

    Daniel:o

  3. #3
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default

    When you are comparing strings in java you need to use the comparison method equals. If you are comparing primitive data types then you would use !=, or ==.

    So the program below is syntactically correct and will exit if you enter e. Not quite sure if this is logically correct from your description of what the program needs to do though.

    Java Code:
    import javax.swing.*;
    public class Garden
    {
        static String product;
        int a,b,c,d;
    
        public static void main (String [] args )
        {
            enterProduct();
            System.exit(0);
        }
    
        public static void enterProduct()
        {
            product=JOptionPane.showInputDialog(null,"Enter e to exit");
    
            while (!product.equals( "e" ))
            {
                product=JOptionPane.showInputDialog(null,"Enter e to exit");
            }
        }
    }
    Greetings

    Marcus:cool:

Similar Threads

  1. Loop Help
    By HeavyD in forum New To Java
    Replies: 7
    Last Post: 09-22-2010, 09:55 PM
  2. while loop
    By michcio in forum New To Java
    Replies: 5
    Last Post: 01-27-2008, 12:56 AM
  3. can you help me with this for loop?
    By java_fun2007 in forum New To Java
    Replies: 6
    Last Post: 12-22-2007, 10:20 AM
  4. A loop that doesn't loop
    By MichYer in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 08:44 AM
  5. While loop
    By leebee in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 03:11 PM

Posting Permissions

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