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

    Post problem in do while loop

    package Third;

    import java.util.Scanner;

    public class Counter extends Thread
    {
    public void run()
    {
    int counter = 0;
    while(!isInterrupted())
    {
    counter++;
    System.out.println(counter);
    try
    {
    sleep(counter);
    }
    catch (InterruptedException e)
    {
    System.out.println("raised Exception handled");
    break;
    }
    }
    }
    }

    class Mgr44
    {
    public static void main(String[] args)
    {
    Counter c1 = new Counter();
    c1.start();
    Scanner sc = new Scanner(System.in);
    String decides = null;
    do
    {
    try
    {
    Thread.sleep(100000);
    }
    catch (InterruptedException e)
    {
    System.out.println(e);
    }
    System.out.println("do u want 2 continue.?(Y)/(N)");
    decides = sc.next();
    }while("y" equals(decides));
    }
    }




    what the mistake i did in the above code.?
    can any one please rply.?
    thanks in advanvce
    Daya

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Dayanand View Post
    }while("y" equals(decides));

    what the mistake i did in the above code.?
    can any one please rply.?
    thanks in advanvce
    One little dot:

    Java Code:
    "y".equals(decides)
    You call the method 'equals' on a String, here it is called on the String "y".

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Dayanand is offline Member
    Join Date
    Feb 2011
    Posts
    61
    Rep Power
    0

Similar Threads

  1. for loop problem
    By donal-ctn in forum JCreator
    Replies: 1
    Last Post: 01-31-2011, 07:26 PM
  2. Problem with a for loop
    By ile4 in forum New To Java
    Replies: 3
    Last Post: 12-02-2010, 02:23 PM
  3. For Loop Problem
    By saqib15 in forum New To Java
    Replies: 6
    Last Post: 02-20-2010, 12:59 AM
  4. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 06:12 AM
  5. Some while loop problem need help
    By shaggyoo7 in forum New To Java
    Replies: 4
    Last Post: 01-14-2009, 07:16 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
  •