(5 + 6) / 2 = ?

Here is my code to calculate the expression (5 + 6) / 2:
public class Trytosee
     public static void main(String[] args)
        double x;
          x = (5 + 6) / 2;
          System.out.println(x);
I got the result from the output Screen: 5.0. I wonder why not 5.5? Could somebody help?

To further elaborate:
(5 + 6) / 2 gives the integer result of 5 which is cast to 5.0 when it is assigned to the double variable x. If you wish to have the result 5.5 stored then you need to change one of the values to float.
x = (5 + 6) / 2.0;

Similar Messages

Maybe you are looking for