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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:07:04+00:00 2026-06-12T11:07:04+00:00

Im working on a CS assignment and Im having a little trouble understanding how

  • 0

Im working on a CS assignment and Im having a little trouble understanding how to output an array of doubles that represent the amt of money in a bank account at increments of time given a user specified growth rate. I have a main method that asks the user for initialAmount of $, a growthRate and the number of time intervals (denoted iA, gR and nP for inital Amount, growth Rate and number of Periods). this method then calls another method which is of return type double[]. My issue is with the code inside my for-loop, it compiles fine but outputs gibberish. heres the code:

import java.util.Scanner;

public class Benford {
    public static double[] generateBenfordNumbers (double iA, double gR, int nP) {  
        double[] bankStatement = new double[nP];

        for (int i = 0; i<nP; i++) { 
            bankStatement[i] = (iA*(Math.pow((1+(gR)), (i++))));
        }

        return bankStatement;
    }

    public static void main (String[] args) {
        Scanner scan = new Scanner(System.in); 
        double iA;
        double gR;
        int nP;

        System.out.print("What is the initial amount of money that you are starting with? : ");
        iA = scan.nextDouble();
        System.out.println();

        System.out.print("What is the amount of growth per time period? : ");
        gR = scan.nextDouble();
        System.out.println();

        System.out.print("How many time periods would you like to use? : ");
        nP = scan.nextInt();
        System.out.println();

        generateBenfordNumbers(iA, gR, nP);
        System.out.print(generateBenfordNumbers(iA, gR, nP));
    }
}
  • 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-12T11:07:05+00:00Added an answer on June 12, 2026 at 11:07 am

    In the line

    bankStatement[i] = (iA*(Math.pow((1+(gR)), (i++))));
    

    i++ increments i a second time. You probably want:

    bankStatement[i] = (iA*(Math.pow((1+(gR)), i + 1)));
    

    or, if we clean it up,

    bankStatement[i] = iA * Math.pow(1 + gR, i + 1);
    

    i + 1 returns a value 1 greater than that of i, but does not actually increment the variable itself.


    Also, do you really have to use Math.pow each time? Can’t you just manually set the first element of your array to iA and subsequently use bankStatement[i-1] to compute bankStatement[i]? Doing something like this will probably improve your program.

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

Sidebar

Related Questions

I'm having this little problem with an ASM assignment I'm working on. It works
I'm having a very weird problem.I'm working on an assignment that involves building a
I am working on a school assignment that requires operator overloading. I am having
I'm having some trouble with an assignment I'm working on. Part of it is
I'm working on my assignment of PHP course. The problem that I don't understand
I am working on an assignment that deals with reading data from a text
I am currently in an introductory c++ class and am working assignment that sorts
Good day, Stack Overflow. I have a homework assignment that I'm working on this
I am working on an assignment that requires me to reimplement all of the
So I'm having issues overloading the assignment operator when working with templates. Basically, I'm

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.