Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6861905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:35:41+00:00 2026-05-27T02:35:41+00:00

I cannot for the life of me understand why this code isn’t working. I

  • 0

I cannot for the life of me understand why this code isn’t working. I am creating a function to evaluate a polynomial at all of the points over a given x interval, at a frequency specified by the user. My underlying Polynomial code is irrelevent to the problem. My problem is filling my array with the values I am obtaining from Horner’s method.

public double[] evalAt(double s, double f, int n) {
    double[] resultArray = new double[n];
    double h =((f - s)/(n));
    if(s==f) {
        double tempResult = 0;
        for (int i = this.degree; i >= 0; i--) {
            tempResult = tempResult * s + this.terms[i].getCoefficient();
        }
        resultArray[0] = tempResult;
    } else {
        int counter = 0;
        for(double i = s; i <= f; i=i+h) {
            double tempResult = 0;
            for (int j = this.degree; j >= 0; j--) {
                tempResult = tempResult * i + this.terms[j].getCoefficient();
            }
            System.out.println("Counter: " + counter + " Result @ Counter: " + tempResult);
            resultArray[counter++] = tempResult;
        }
        System.out.println(resultArray[0]);
        System.out.println(resultArray[1]);
        System.out.println(resultArray[2]);
        System.out.println(resultArray[3]);
    }
    return resultArray;
}

I have a print statement in there to show me what the values of the counter and the temporary result are. then I use the resultArray['index'] = 'value'; syntax. When I run this, I see that the counter and the value are exactly as I want them, however when I check the array with the four print statements at the bottom, nothing happens. My inputs are 0,10,10:

Output:

Counter: 0 Result @ Counter: 0.0
Counter: 1 Result @ Counter: 1.0
Counter: 2 Result @ Counter: 4.0
Counter: 3 Result @ Counter: 9.0
Counter: 4 Result @ Counter: 16.0
Counter: 5 Result @ Counter: 25.0
Counter: 6 Result @ Counter: 36.0
Counter: 7 Result @ Counter: 49.0
Counter: 8 Result @ Counter: 64.0
Counter: 9 Result @ Counter: 81.0
Counter: 10 Result @ Counter: 100.0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:35:42+00:00Added an answer on May 27, 2026 at 2:35 am

    I strongly suspect it is throwing an ArrayIndexOutOfBoundsException which is getting swallowed outside this method.

    You are creating an array of size n, in this case 10, but your counter goes from zero to f (also 10) which is a total of 11 elements. So there’s an off-by-one in at least one of those.

    Look through your code and find the bit that says

    catch (Exception e) {
    }
    

    and change it to

    catch (Exception e) {
        e.printStackTrace();
    }
    

    to help catch this kind of error more easily.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, and for the life of me, I cannot understand
I cannot for the life of me get this. Example of fails, the last
I understand BFS, and DFS, but for the life of me cannot figure out
For the life of me I cannot understand why the compiler won't let me
I cannot for the life of me attach the java source code to eclipse
last resort this as I cannot for the life of me work it out!
This may be a n00b question, but I cannot for the life of me
I cannot for the life of me figure out how to do this: I
I cannot for the life of me figure out why my table is turning
I think I might be overtired but I cannot for the life of me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.