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

  • SEARCH
  • Home
  • 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 7742725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:20:56+00:00 2026-06-01T09:20:56+00:00

I came across this post pass array to method Java on how to pass

  • 0

I came across this post ” pass array to method Java ” on how to pass an array to a method however when trying to adapt it to my intrest calculator Ive got going I get errors such as “the operator / is undefined for the argument types double[],double” and I am unable to get it resolved. I am also looking to return the whole array since I need to print the results later on and eventually sort them.

For example I define my arrays and how big they can be and then call on the user to input loan amount, interest, and frequency calculated. After I get the data and its all in array format I then pass the whole arrays off to calculate simple interest and want to return the results as an array, and then pass the same initial arrays to find compound interest by month, week, and day but I get the previously mentioned error when it tries to do the division involved in “A = P(1+ (r/n))^(n*t)” The gathering data works fine I just cannot seem to pass arrays correctly or loop through them once I do IF I’m passing them right

Any and all assistance is appreciated as always.

Relevent code

call data from user

do {
        arrPrincipalAmt[i] = getPrincipalAmount();
        arrInterestRate[i]= getInterestRate();
        arrTerm[i] = getTerm();
        i++;
        if (i < 4)
        {
          /*
           * if "i" comes to equal 4 it is the last number that will fit in the array of 5
           * and will Skip asking the user if they want to input more
           */

          System.out.println("Enter another set of Data? (Yes/No):");
          boolean YN = askYesNo();
          if (YN == true)
          {
            more = true;
          }
          else if (YN == false)
          {
            more=false;
          }
        }
        else
        {
          more = false;
        }
      }while(more);


      while (run)
      {

        //Start calculations call methods
        final int dINy = 365; //days in year
        final int mINy = 12; //months in year
        final int wINy = 52; //weeks in year
        double loanYears =(double) arrTerm[i]/mINy; //convert loan months into fraction of years, or whole years with decimals.
        arrSimple= calculateSimpleInterest(arrPrincipalAmt, arrInterestRate,loanYears);
        //Simple IntrestloanAmount * (annualInterestRate/100.0) * loanYears;
        arrCompoundMonthly = calculateCompundInterest(arrPrincipalAmt, arrInterestRate,mINy,loanYears);
        //rewrite month compound:loanAmount * Math.pow((1+((annualInterestRate/100)/mINy)),(loanYears*mINy)) - loanAmount;

simple interest that fails

public static double[] calculateSimpleInterest(double[] arrPrincipalAmt, double[] arrInterestRate, double Years)
  {
    for(int i=0; i<arrPrincipalAmt.length; i++)
    {
      double simpInterest= arrPrincipalAmt[i] * (arrInterestRate[i]/100.0) * Years; //Simple Interest Calculation
    }
    return simpInterest;
  }

compound interest that fails

 public static double[] calculateCompundInterest(double[] arrPrincipalAmt, double[] 

arrInterestRate, double frequency, double time)
  {
    /*The Compound Interest calculation formation is as follows:A = P(1+ (r/n))^(n*t) - P
     A = total interest amount only.
     P = principal amount (loan amount or initial investment).
     r = annual nominal interest rate (as a decimal not a percentage).
     n = number of times the interest is compounded per year.
     t = number of years (don't forget to convert number of months entered by user to years).
     */
    for (int i=0; i < arrPrincipalAmt.length; i++)
    {
      double[] compound= arrPrincipalAmt[i] * Math.pow((1+(arrInterestRate[i]/100.0)/frequency),(frequency*time)) - arrPrincipalAmt[i]; //Compound Interest  monthly, weekly and daily depending on the frequency passed
    }
    return compound;
  }
  • 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-01T09:20:58+00:00Added an answer on June 1, 2026 at 9:20 am

    i checked your code and the problem is that at line 227 you define compound as a double array while the result of the expression at that line is simply a double.
    I think you want to do so:

    double[] compound = new double[arrPrincipalAmt.length];
    
    for (int i=0; i < arrPrincipalAmt.length; i++) {
        compound[i] = arrPrincipalAmt[i] * Math.pow((1+(arrInterestRate[i]/100.0)/frequency),(frequency*time)) - arrPrincipalAmt[i];
    }
    
    return compound;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whilst trying to pivot a sql table I came across this post Here .
While browsing I came across this blog post about using the Wikipedia API from
Well I was reading this post and then I came across a code which
Kicking around some small structures while answering this post , I came across the
While stumbling through the chromium code documentation, I came across this post: http://code.google.com/p/chromium/wiki/UsingGit#Windows If
i came across this post where Reader Comment #16 mentions: The ringtone syncing functionality
I came across this post , which reports the following interview question: Given two
i came across this post http://www.webmasterworld.com/javascript/3066162.htm about how in javascript when you instantiate an
I'm investigating different optimization techniques, and I came across this post Analyzing Code for
In my quest for looking for a BigInt library, I came across this post:

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.