-1

I would expect System.out.println(13 / 31) to print 0.419354838709677.

It prints 0.0. Why?

Scruffy
  • 579
  • 8
  • 23

1 Answers1

1

because you are dividing an int with an int therefore the result will be an int

try

System.out.println(13.0 / 31)

or

System.out.println((float)13 / 31)
Scary Wombat
  • 43,525
  • 5
  • 33
  • 63