-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
  • 94,125
  • 30
  • 188
  • 241
Aster Veigas
  • 866
  • 3
  • 13
  • 34
1

Try this:

xinc = (double)dx/len;

Also, before posting, Google.

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

Matt Clark
  • 27,671
  • 19
  • 68
  • 123