-1

This must be pretty basic Java question but I can't get why below program outputs 1.0:

public class Testing {

    public static void main(String args[]) {
        int width = 1920;
        int height = 1080;
        double ratio = width / height;
        System.out.println("Ratio: " + ratio + "");
    }
}

I expect no surprises.

VPZ
  • 602
  • 7
  • 18

1 Answers1

1

You are doing integer division, and assigning the result to a double. If you want floating point division, at least one of the arguments must be a floating point value (as @Eugene suggests).

Scott Hunter
  • 44,196
  • 8
  • 51
  • 88