Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Run time error

  1. #1
    Junior Member moodycrab3's Avatar
    Join Date
    Feb 2011
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Run time error

    class yam
    {
    public static void findIndex()
    {
    String s="allendowlley";
    int index=0;
    int l=s.length();
    while(index<l)
    {
    index=s.indexOf('l',index);
    System.out.println(index);
    index=index+1;
    }
    }
    public static void main(String args[])
    {
    findIndex();
    }
    }
    The program keeps looping endlessly. I can't figure out why.


  2. #2
    Member
    Join Date
    Feb 2011
    Posts
    33
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Run time error


    I was able to end the infinite loop but I'm not sure if the output is still what you're looking for. I'm still kind of new to the Java scene. I replaced the while loop with a for loop...

    class yam
    {
    public static void findIndex()
    {
    String s="allendowlley";
    int index=0;
    int l=s.length();
    for(int i = 0; i<l; i++)
    {
    index = i;
    index=s.indexOf('l',index);
    System.out.println(index);
    index=index+1;
    }
    }
    public static void main(String args[])
    {
    findIndex();
    }
    }


Similar Threads

  1. 1st time using methods
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 1st, 2010, 01:37 PM
  2. [SOLVED] Experiencing a run time error, don't know what the problem is
    By scooty199 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 3rd, 2010, 10:21 AM
  3. Using time
    By ellias2007 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 4th, 2010, 08:48 AM
  4. Struts Application, Complies perfectly but error at run time
    By Prarthana in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 18th, 2010, 01:49 AM