Results 1 to 3 of 3
  1. #1
    arvind1508 is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Lightbulb Help with loop statement

    I have made a simple retail shop programme, coded as given:
    import java.io.*;
    class Retail1{
    public static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[]arg) throws IOException
    {
    String ip;
    int quantity, rate , price, total;
    do {System.out.println(" Enter item name");
    String item = stdin.readLine();
    System.out.println(" Enter quantity ");
    quantity = Integer.parseInt(stdin.readLine());
    System.out.println(" Enter rate");
    rate = Integer.parseInt(stdin.readLine());
    System.out.println(" Are the more items yes/no ? ");
    more = stdin.readLine() ;
    price = rate*quantity;
    total = 0;
    total = total + price;
    }while(more == "yes");
    System.out.println(" Amount to be paid = " + total);
    System.out.println(" Amount paid = ");
    int amtpaid = Integer.parseInt(stdin.readLine());
    int bal = amtpaid - total;
    System.out.println(" Balance = " + bal);
    }
    }

    But when i run it, whether i type yes or no for the 'more' string, it is skipped and the program continues to the amt to be paid

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    use equals instead of == !! strings are objects

    --> } while ("yes".equals(more));

  3. #3
    arvind1508 is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

Similar Threads

  1. An "if" statement inside a "for" loop?
    By soccermiles in forum New To Java
    Replies: 18
    Last Post: 04-20-2010, 03:44 AM
  2. Vote - Favorite Loop Statement
    By angryboy in forum New To Java
    Replies: 24
    Last Post: 02-15-2009, 08:15 PM
  3. Need help with a loop statement
    By sunshine39 in forum New To Java
    Replies: 7
    Last Post: 11-03-2008, 03:42 AM
  4. Least To Greates[ if statement and for loop]
    By kris09 in forum New To Java
    Replies: 1
    Last Post: 08-08-2008, 06:34 PM
  5. Beginner's Problem on Loop/If statement
    By obdi in forum New To Java
    Replies: 2
    Last Post: 07-07-2008, 01:41 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
  •