本文介绍了在java中获取double值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用这个公式得到总数,(count / 9)*(30/100)。
但这是我得到的输出
输出:0。 0
I want to get the total number by using this formula, (count/9)*(30/100).
But this is the output I get
Output: 0 . 0
private void CountMatching(Object[] array, Object[] array1) {
int count = 0;
double total;
for (int a = 0; a < array.length; a++) {
for (int b = 0; b < array1.length; b++) {
if (array[a] == array1[b]) {
count++;
}
}
}
System.out.println(count);
total=(count/9)*(30.0/100);
System.out.println(total);
}
推荐答案
Quote:
total =(count / 9)*(30.0 / 100);
total=(count/9)*(30.0/100);
在上面一行(count / 9)
使用整数除法,因为两个操作数都是整数。更改为
In the above line (count/9)
is evaluated using the integer division, since both the operands are integers. Change to
total=(count/9.0)*(30.0/100);
为了获得预期的结果。
double count = 0.0d;
这篇关于在java中获取double值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!