把x,y定义成float,或者x/2.0算术运算中至少有一个参数是浮点数,结果才是浮点数,都是int,结果也是int
//方法1 sum = (float)x / 2 + (float)y / 2; //方法2 sum = x / 2.0f + y / 2.0f;