Results 1 to 3 of 3
  1. #1
    zoe
    zoe is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Using int/int, 7/5 would return 1

    I'm programming in Java. I'm trying to make a program that inputs money (as a double) and determines the amount of different coins to give.
    My problem is, I input a value as a double, and try to divide by a number to get the number of times it goes into that number, and get a remainer.
    For example, using int/int, 7/5 would return 1.
    But dividing double/double 7.0/5.0 returns an exact double. How to i get int "1" out of that?
    Thanks.

  2. #2
    Seemster is offline Member
    Join Date
    Jul 2007
    Posts
    55
    Rep Power
    0

    Default

    double x = 12;
    int y = new Double(x).intValue();

  3. #3
    Deepa is offline Member
    Join Date
    Nov 2008
    Posts
    85
    Rep Power
    0

    Default Re:

    Hi,
    If u use below code,U must get the output as 1.

    double q=7.0;
    double w=5.0;
    double s=(q/w);
    int r=new Double(s).intValue();

Similar Threads

  1. there is no return statement
    By gabriel in forum New To Java
    Replies: 17
    Last Post: 12-03-2008, 05:55 PM
  2. return out of scope?
    By another_steve in forum New To Java
    Replies: 5
    Last Post: 01-28-2008, 10:34 PM
  3. if..else..return
    By mqdias in forum New To Java
    Replies: 1
    Last Post: 08-10-2007, 05:20 PM
  4. Return value of method
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 09:23 AM
  5. Return to try block
    By Freddie in forum New To Java
    Replies: 2
    Last Post: 05-11-2007, 09:58 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
  •