本文介绍了有关使用Double变量进行Java计算的初学者查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑,也许有人能够解释它;在以下3个命令中...

Hi, I am a bit confused with something, perhaps somebody is able to explain it; in the following 3 commands ...

double z1 = (double) ( 12 / 5 );
System.out.println( z1 ); // = 2.0





double z2 = 12 / 5;
System.out.println( z2 ); // = 2.0





double z3 = (double) 12 / 5 ;
System.out.println( z3 ); // = 2.4



...似乎只有第三个可以正确计算.

如果将变量定义为Double,是否不告诉系统它是带有小数位的数字变量?如果是这样,为什么前2条语句给出的结果不正确?!?



... only the third one seems to do the correct calculation.

If a variable is defined as a Double, are you not telling the system that it is a numeric variable with decimal places ? If so, why do the first 2 statements give an incorrect result ?!?

推荐答案


这篇关于有关使用Double变量进行Java计算的初学者查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:41