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 5 of 5

Thread: Unending Loop Issue? Can't find it.

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Unending Loop Issue? Can't find it.

    Although I think this is an issue with my loops structure/conditions this could also be an issue with how Java does arithmetic. I'm sure this is probably simple but I can't find it right now.
    The polynomial object is composed of an array of size 100 which stores the coefficients of a polynomial in index locations corresponding to the power of each respective term. The purpose of this code is to create a new polynomial object which is the result of multiplying two polynomials.
    I'm pretty sure that the loop is not ending but I'm not sure why. The initial S.o.ps of i+j values are what I expect but then they go into enormous negative numbers and I have no idea why.
      public Polynomial mult(Polynomial p)
                        throws ExponentOutOfRangeException
      {
          Polynomial multiPolynomial = new Polynomial();
     
     
          //Start testcode
          System.out.print("this polynomial ");
          this.displayPolynomial();
          System.out.print("p polynomial ");
          p.displayPolynomial();
          //End testcode
     
     
          for(int i = 0; i < 99; i++)
          {
              for(int j = 0; j < 99; i++)
              {
                if((i+j) < MAX)
                {
                    multiPolynomial.polyArr[i + j] = multiPolynomial.polyArr[i + j] + (this.polyArr[i] * p.polyArr[j]);
                }
              }
          }
       // Multiplies polynomial p to this polynomial without modifying this
       // polynomial and returns the result.
       // Precondition: None.
       // Postcondition: The returned polynomial is the product of this 
       // and p.  Both this and p are unchanged.
       // Throws: ExponentOutOfRangeException if exponent is out of range.
          return multiPolynomial;
      }
    By the way,
    Last edited by helloworld922; March 4th, 2011 at 08:01 PM.


  2. #2
    Junior Member
    Join Date
    Feb 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unending Loop Issue? Can't find it.

    Thanks to whoever fixed the way the code displays here. I was looking up the necessary tags just now. Anyone see the problem? Maybe I should include more code...

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Unending Loop Issue? Can't find it.

    for(int j = 0; j < 99; i++)
    You're incrementing i in the j loop, not j

  4. The Following User Says Thank You to helloworld922 For This Useful Post:

    javapenguin (March 4th, 2011)

  5. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Unending Loop Issue? Can't find it.

    You seem to be incrementing i twice.

    Perhaps you should change it to j++;

    As it is, i is being incremented twice and j is stuck at 0.

    Musta posted at same time as helloworld922.

    Oh well.

  6. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unending Loop Issue? Can't find it.

    Omigosh, how embarrassing! I looked at the problem is sooo many ways and I missed that simple item. I guess that's why you ask other people to look at code. Thanks guys!

Similar Threads

  1. Basic loop issue
    By Nismoz3255 in forum Loops & Control Statements
    Replies: 3
    Last Post: February 23rd, 2011, 05:10 PM
  2. Java uberNoob, requesting help with simple loop issue
    By miketeezie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2011, 09:13 PM
  3. Port issue?
    By Brt93yoda in forum Java Theory & Questions
    Replies: 3
    Last Post: October 13th, 2010, 04:28 PM
  4. Weird issue with while loop ending/being skipped
    By ang3c0 in forum Loops & Control Statements
    Replies: 4
    Last Post: December 25th, 2009, 12:09 PM
  5. Issues with Tomcat 6.0
    By sanyog24681 in forum Java Servlet
    Replies: 0
    Last Post: October 21st, 2008, 07:55 AM

Tags for this Thread