除法时输出为零? [英] Output is zero when dividing?
本文介绍了除法时输出为零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
也许我看不到明显的东西,但是:
Maybe I can't see obvious thing but:
int x1 = 2;
int y1 = 4;
int x2 = 11;
int y2 = 7;
double res = (y2-y1)/(x2-x1);
System.out.println(res);
输出:
0.0
为什么?
推荐答案
您首先需要将这些变量定义为double值,并且应该可以使用。
you need to initially define those variables as doubles and it should work.
这篇关于除法时输出为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文