Notices
Results 1 to 5 of 5

Thread: Programming help

  1. #1 Programming help 
    New Member
    Join Date
    Jan 2011
    Posts
    2
    Suppose that you have a variable that holds a monetary value in cents. Write statements in Java that will compute the number of $1000 , $1 and 1 cent needed to compose the amount.


    Attempt :

    we take a random number ( 43,567 ) and assign it to int cents ?

    $1000 x 43567 = 43 times ( 40,000) ?

    i am not sure how to go about it, any help will be appreciate .


    Reply With Quote  
     

  2.  
     

  3. #2  
    New Member
    Join Date
    Jan 2011
    Posts
    2
    bump :/


    Reply With Quote  
     

  4. #3  
    Forum Freshman
    Join Date
    Oct 2010
    Posts
    98
    It sounds like a knapsack problem. Try greedy algorithm.
    Reply With Quote  
     

  5. #4 No otherway 
    Forum Freshman
    Join Date
    Jan 2011
    Posts
    6
    You'll have to use utils.math.Integer library for such a big number !
    Reply With Quote  
     

  6. #5  
    Forum Freshman
    Join Date
    Feb 2011
    Posts
    15
    I think you want to divide...

    If your var holds the number of cents (pennies) then you would want something like this:

    int OriginalValue = 43567;
    int NumOfDollars = 43567 / 100; //should equate to 435
    int NumOfCents = 43567 % 100; //Should give you the remainder, 67

    So from that number of cents you have 435 $1 and 67 Pennies.

    Lets try a bigger number, say 443567

    int OriginalValue = 443567;
    int NumOfDollars = 443567 / 100; //should equate to 4435
    int NumOfThousands = NumOfDollars / 1000; //Should equal 4
    NumOfDollars = NumOfDollars - NumOfThousands; // Should Equal 435

    int NumOfCents = 443567 % 100; //Should give you the remainder, 67

    So you now have 4 $1000, 435 $1 and 67 Pennies.

    Does that work for you?

    TN
    Reply With Quote  
     

Bookmarks
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
  •