Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: JAVA program help : 1+1!+1/2!+1/3!+ .... 1/N!?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation JAVA program help : 1+1!+1/2!+1/3!+ .... 1/N!?

    Im using Blue J for Java. Please help me on how to write the program for 1+1!+1/2!+1/3!+ .... 1/N! in Java.

    Thank you.


    I would also appreciate if you could help me for:
    2) x- x^2/2! + x^4/4! - X^6/6! - x^8/8!
    3) x/10! + X^2/9! + x^3/8! + x^4/7! + x^5/6!


    Please help me. Its 2 AM here in india, and my class is at 6:30 AM.


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: JAVA program help : 1+1!+1/2!+1/3!+ .... 1/N!?

    Please help me. Its 2 AM here in india, and my class is at 6:30 AM.
    Sure, here you go:
    http://www.amazon.co.uk/s/ref=nb_sb_...o+view&x=0&y=0
    and also:
    Go to sleep. Even if someone haz teh codez, no tutor will believe it is your work if you are unable to talk through exhaustion tomorrow. Maybe showing your tutor my comment will help defuse some of the tension?

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JAVA program help : 1+1!+1/2!+1/3!+ .... 1/N!?

    Ok, nevermind.

    For example, if I declare an int n, is it possible to :

    Math.pow (5,n+2) ;

    Just this one doubt please!

  4. #4
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: JAVA program help : 1+1!+1/2!+1/3!+ .... 1/N!?

    Specific examples we can help with!
    You can of course do what you just posted, but it won't help you (I think) compute (1-to-N)! What you really need to do is to write a method with a signature like 'public static int factorial(int theNumber)' which will multiply theNumber by all numbers smaller than itself and greater than 1. Then you'd write a loop that did the sum of all the reciprocals of factorials from 1 to N.

  5. The Following User Says Thank You to Sean4u For This Useful Post:

    siddharthbandhu (June 6th, 2012)

  6. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JAVA program help : 1+1!+1/2!+1/3!+ .... 1/N!?

    Quote Originally Posted by Sean4u View Post
    Specific examples we can help with!
    You can of course do what you just posted, but it won't help you (I think) compute (1-to-N)! What you really need to do is to write a method with a signature like 'public static int factorial(int theNumber)' which will multiply theNumber by all numbers smaller than itself and greater than 1. Then you'd write a loop that did the sum of all the reciprocals of factorials from 1 to N.
    That was just an example. No way related to the program above.
    Im just happy that it will work, thanks alot!

  7. #6
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: JAVA program help : 1+1!+1/2!+1/3!+ .... 1/N!?

    It'll work because Math.pow is pow(double a, double b):
    Math (Java Platform SE 6)
    'n + 2' is an expression whose value is int if n is an int and double if n is a double (the '2' is an int and would be 'promoted' to double if n is double so that double+double=double can be computed). 5 is an int, so the Java compiler will perform a 'widening primitive conversion' on 5 (and on the result of n + 2, if needed) so that the method invocation matches the Math.pow method signature:
    Conversions and Promotions

Similar Threads

  1. how to run a java program..when the program using jar
    By miriyalasrihari in forum Java Theory & Questions
    Replies: 2
    Last Post: May 17th, 2012, 11:04 AM
  2. Help with tic tac toe java program?
    By Momar99 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 6th, 2011, 11:47 PM
  3. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 07:32 AM
  4. How do you add GUI to this java program?
    By leyla in forum AWT / Java Swing
    Replies: 1
    Last Post: October 18th, 2009, 02:32 PM
  5. Convert Java Program to Java ME code
    By rinchan11 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: October 5th, 2009, 11:18 PM

Tags for this Thread