Results 1 to 2 of 2

Thread: Looping problem

  1. #1
    Tanilo is offline Member
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Default Looping problem

    the following will not loop i don't get why

    import java.util.*;
    import java.io.*;

    public class CAITest
    {
    public static Scanner input = new Scanner(System.in);

    public static void main(String args[])
    {

    CAI cai = new CAI();
    String keepGoing = "y";


    do
    {
    cai.generateQuestion();
    cai.userAnswer = input.nextInt();

    cai.checkResult();
    input.nextLine();
    keepGoing = input.next();
    }
    while(keepGoing == "y");
    }
    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes this not looping. You have set to exit the loop at the first time. To loop this change the while condition as follows.

    Java Code:
    while(!keepGoing.equals("y"));

Similar Threads

  1. Class Scanner looping issue
    By Stev0 in forum New To Java
    Replies: 1
    Last Post: 05-25-2008, 07:53 PM
  2. Looping ArrayList
    By hai789 in forum Web Frameworks
    Replies: 5
    Last Post: 05-07-2008, 04:55 AM
  3. Can't solve error message while looping
    By BHCluster in forum New To Java
    Replies: 15
    Last Post: 04-22-2008, 11:51 AM
  4. Java Looping and decision
    By susan in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:29 AM
  5. looping a function
    By Username in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 06:37 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
  •