是否有我可以在 java 中使用的 python 中使用的//运算符形式,或者某种解决方法? 10//3 = 3
最佳答案
在python 3中//
默认作为楼层划分。
在 python 2.2 和更高版本的 2.X 版本中,我们可以从 __future__
>>> from __future__ import division
>>> 10/3
3.3333333333333335
>>> 10//3
3
在Java中: 当除以浮点变量或值时,答案的小数部分用浮点变量表示。
float f = 10.0f / 6.0f; // result is 1.6666
double d = 10.0 / 9.0; // result is 1.1111
但对于 java 中的 floor:
(int)Math.floor(10/3);
关于java - Java 中的运算符就像//在 python 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27217401/