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 8825499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:53:37+00:00 2026-06-14T06:53:37+00:00

I am working on a java project and I have a loop that is

  • 0

I am working on a java project and I have a loop that is driving me crazy.

The program takes an input, N, which is a positive integer. What I want my loop to do is this:

Lets say that N = 10. The loop will take all numbers from 1 to 10, raise it to the fifth power, and store each value in an array of length N.

It works (seemingly) correctly up until N = 73, I think. Once N hits 74 or above it starts to randomly give me negative numbers for 74^5. Which obviously is incorrect. The higher the number, the more negatives it gives me.

private static int _theLimit = EquationSolver.getLimit(); //input "N"
private static int length = (int) (_theLimit); //length of possible solutions array = N
static int[] _solutions = new int[length]; 

public static void solutionRun() {
    for(int i = 1; i <=_theLimit ;) { 
        //theLimit refers to the input N; for numbers from 1 until N
        for (int p = 0; p <= _solutions.length-1; p++) { 
            //solutions is an array that stores all possible solutions to ^5 from 1 to N; 
            _solutions[p] = i*i*i*i*i; 
            //p refers to the array location, increments with each new i
            i++;
        }           
    }
    for(int q = 0; q<=_solutions.length-1; q++){ //outputs solutions for debugging purposes
        System.out.println(_solutions[q]);
    }
}
  • 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-06-14T06:53:38+00:00Added an answer on June 14, 2026 at 6:53 am

    The problem is that you just passed the range that integer allows.

    Int allow numbers from -2,147,483,648 to a maximum value of 2,147,483,647 (inclusive) (source), since 74^5 = 2,219,006,624. Thus, more that the Int can handle.

    If you want a bigger range you can use java BigInteger Class. A code example:

    BigInteger pow(BigInteger base, BigInteger exponent) {
      BigInteger result = BigInteger.ONE;
      while (exponent.signum() > 0) {
        if (exponent.testBit(0)) result = result.multiply(base);
        base = base.multiply(base);
        exponent = exponent.shiftRight(1);
      }
      return result;
    }
    

    Considerations: This may not be very efficient and might not work for negative bases or exponents. Use it as an example on how to use BigIntegers.

    Instead of BigInteger, you can also use the long type that vary from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (inclusive) (source).

    Do not use double for this purpose, since you can have precision problems.

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

Sidebar

Related Questions

I'm working on a java project in Netbeans. I have a for loop which
I'm working on a Java project where I have created a class that looks
I am working on a Java project where I have an ant build, which
I am working on a Java project that I want to deliver to my
I am working on a Java project in which I have to use a
I'm currently working on a Java project which uses Tibco rendezvous control. I have
I'm working on a Java project in which I have the getter method below
I am working on a Java project and need to have a keypress simulate
I'm working on code for a Java project, I currently have replaceAll(String, int) in
I have created a couple of java working sets for a project in my

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.