-2

I'm a newbie in Java. this is a part of my program. i should get a 0.65 as a result but java result is 0.0. how to solve it?

    double xinc;
    int dx = 190;
    int len = 290;
    xinc = dx/len;
    System.out.println(xinc);
HFDev
  • 131
  • 2
  • 4
  • 11

2 Answers2

2
int/int = int

You have to make dx and len as double in order to get a double result else you can also type cast dx and len to double.

Maroun
  • 91,013
  • 29
  • 181
  • 233
Aster Veigas
  • 836
  • 2
  • 13
  • 33
1

Try this:

xinc = (double)dx/len;

Also, before posting, Google.

int / int = int
int / double = double
double / int = double

Matt Clark
  • 26,491
  • 18
  • 65
  • 118