Results 1 to 3 of 3

Thread: Help with Math.pow using variable

  1. #1
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help with Math.pow using variable

    Hi Guys,

    I need help on how to use inputs for the Math.pow class which is represented by the variable n(the number of years).

    public class ComputeInterest {
    public static void main(String[ ] args) {

    double L = Double.parseDouble(args[0]);
    double i = Double.parseDouble(args[1]);
    double n = Double.parseDouble(args[2]);


    double C = L * (1 + i/100)n; // <<the power of n should be placed as follows.



    System.out.println(C);

    }}

    Regards,
    John

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Math is a class. Math.pow is a method. Capital letters are conventionally reserved for classes.
    Code:
    public class ComputeInterest {
        static double computeInterest(double loan,
                                      double interest,
                                      double years) {
            return loan * Math.pow(1 + interest/100, years);
        }
    
        public static void main(String[] args) {
            System.out.println(
                computeInterest(Double.parseDouble(args[0]),
                                Double.parseDouble(args[1]),
                                Double.parseDouble(args[2])));
        }
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. The Following User Says Thank You to Twey For This Useful Post:

    onedollartotown (01-21-2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi Twey. Thanks for the help. Works like charm.

Bookmarks

Posting Permissions

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