Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By lenois
  • 1 Post By JosAH

Thread: Need Help With Equation in Java

  1. #1
    Alsark is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Need Help With Equation in Java

    I just started Java and this is probably a dumb question. I am trying to put the following equation into Java:



    In Java I typed the following (this is just a test program, my actual one has commenting/prompts):

    final double FACTOR = -1/30;
    double b = 0.0;
    double n = 0.0;
    double p = 0.0;
    double dailyInterest = 0.0;
    double apr = 0.0;

    apr = kb.nextDouble();

    b = kb.nextDouble();

    p = kb.nextDouble();

    dailyInterest = apr/365;

    n = FACTOR*((Math.log(1+(b/p)*(1-(Math.pow(1+dailyInterest,30)))/Math.log(1+dailyInterest))));

    I've tried to break it apart a few different ways and as separate variables to clean it up, but the answer I get is always "NaN" for my n value (the values I am trying to use are 13.65 for apr, 2013 for b, and 25 for p; test values provided by the professor).

    Any ideas on why this would be occurring?

  2. #2
    lenois is offline Member
    Join Date
    Feb 2012
    Posts
    59
    Rep Power
    0

    Default Re: Need Help With Equation in Java

    check the value of Factor, I didn't have time to compile and test it out, but if what you wrote is exactly what you had, you may have a data type issue.

    so put this somewhere:

    System.out.println(FACTOR);

    edit I imagine you know what i am pointing out since all of your other values are properly initialized.
    Last edited by lenois; 02-08-2013 at 03:01 AM.
    Fubarable likes this.

  3. #3
    Alsark is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Re: Need Help With Equation in Java

    Quote Originally Posted by lenois View Post
    check the value of Factor, I didn't have time to compile and test it out, but if what you wrote is exactly what you had, you may have a data type issue.

    so put this somewhere:

    System.out.println(FACTOR);

    edit I imagine you know what i am pointing out since all of your other values are properly initialized.
    It looked like FACTOR as a fraction as outputting zero; however, even changing that to a decimal of -.013333333333, the output of my equation is still NaN...

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need Help With Equation in Java

    If 'apr' is 'annual percentage' then i= (apr/365)/100;

    kind regards,

    Jos
    Alsark likes this.
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Alsark is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Re: Need Help With Equation in Java

    Quote Originally Posted by JosAH View Post
    If 'apr' is 'annual percentage' then i= (apr/365)/100;

    kind regards,

    Jos
    Thank you! I did (apr/100)/365 and it seems that the equation is working now!

Similar Threads

  1. Replies: 4
    Last Post: 07-08-2011, 06:35 AM
  2. Math equation in Java Applet
    By calnastic in forum New To Java
    Replies: 10
    Last Post: 06-23-2011, 07:36 AM
  3. converting an algebraic equation to Java
    By fsuarjun03 in forum New To Java
    Replies: 2
    Last Post: 03-09-2010, 07:58 PM
  4. Help with an equation in java
    By coco in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:47 AM
  5. Help with quadratic equation in java
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •