Results 1 to 5 of 5
  1. #1
    debobbt is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default Please I need the solution to this

    Please, help me.I am new to java



    1. Write a function named countRepresentations that returns the number of ways that an amount of money in American dollars can be represented in American bills. The signature of the function is:
    int countRepresentations(int numDollars)
    For example countRepresentations(12) should return 4 because 12 dollars can be represented in the following four ways.
    12 one dollar bills
    1 five dollar bill plus 7 one dollar bills
    2 five dollar bills plus 2 one dollar bills
    1 ten dollar bill plus 2 one dollar bills
    For this question assume that American bills occur only in denominations of 1, 5, 10 and 20 dollar bills.
    Hint: Use a nested loop that looks like this. Please fill in the blanks intelligently, i.e. minimize the number of times that the if statement is executed.



    2. The mathematical constant pi can be approximated using the following infinite sequence:
    4 - 4/3 + 4/5 - 4/7 + 4/9 .... + (4*(-1)n)/((2*n)+1). This was discovered around 1400 by the Indian mathematician Madhavan Namboodiri and was rediscovered by Gottfried Liebniz about 300 years.
    Write a function named approximatePI that returns the value of this sequence after a given number of iterations. If the number of iterations is less than or equal to 0, the function should
    return -1.
    The function prototype is
    double approximatePI(int numIterations)
    Important: There is no operator for exponentiation in Java, C#, C++ or C. In particular ^ is not the operator for exponentiation, it is the operator for exclusive or. If you use ^ for exponentiation you will receive no credit for your answer.
    Examples
    numIterations return Sequence
    0 -1
    1 4 4
    2 2.666667 4 - 4/3
    3 3.466667 4 - 4/3 + 4/5
    4 2.895238 4 - 4/3 + 4/5 - 4/7
    5 3.339683 4 - 4/3 + 4/5 - 4/7 + 4/9
    6 2.976046 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11
    100,000 3.141583 Sequence has 100,000 members


    3. An array is defined to be zero-shifted if all zeros (if any) occur at the end of the array. For example, {3, 1, -4, 0, 0}, {0, 0, 0} and {1, 2, 3} are zero-shifted arrays but {0, 0, 1, 2, 0, 0, 0} and {1, 2, 0, 3, 4, 0} are not. Write a function named isZeroShifted that returns 1 if its array argument is a zero-shifted array, otherwise it returns 0.
    If you are writing in Java or C#, the function prototype is
    int isZeroShifted(int[ ] a)
    If you are writing in C or C++, the function prototype is
    int isZeroShifted(int a[ ], int len) where len is the number of elements in a
    Examples
    a return reason
    {4, -1, 2, 6, 0, 0, 0} 1 All zeroes are at the end
    {1, 0} 1 All zeroes are at the end
    {1, 1, 1, 1, 0, 0} 1 All zeroes are at the end
    {0, 0, 0} 1 The definition of a zero-shifted array does not require that there be non-zero elements in the array.
    {1, 2, 3} 1 The definition of zero-shifted array does not require that there be zero-valued elements in the array. All it says is that if there are zero-valued elements they must all be at the end.
    {} 1 Since neither zeroes or non-zeroes are required, this is okay.
    {1, 2, 0, 3} 0 Not all zeroes are at the end.
    {0, 0, 0, 1} 0 Not all zeroes are at the end.
    {0, 1, 0} 0 Not all zeroes are at the end
    {0} 1 All zeroes are at the end

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Nobody will do your work. Follow the link in my signature.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    zeesniper is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default

    I need a solution for that too....

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,569
    Rep Power
    12

    Default

    @Z: If you're interested in Java to be wanting to pass tests and things, why waste your time with pointless posts when the OP of this thread has given you a great opportunity by posing tasks for which you could write some code?

    @Both: "Please, help me"? That's like saying "Please help me to lose weight by exercising for me." The point of tasks like the ones posted here is that you benefit by writing the code. Yourself. And once you start you will be in a position where others can help.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Please give me a solution
    By ivvgangadhar in forum AWT / Swing
    Replies: 5
    Last Post: 11-14-2008, 02:43 PM
  2. solution for my project
    By shkelqa in forum AWT / Swing
    Replies: 4
    Last Post: 05-28-2008, 11:31 PM
  3. solution for my project
    By themburu in forum Java Applets
    Replies: 4
    Last Post: 05-21-2008, 02:03 PM
  4. Please need solution
    By prithvi in forum New To Java
    Replies: 4
    Last Post: 04-22-2008, 02:27 PM
  5. Replies: 1
    Last Post: 06-15-2007, 05:42 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
  •