我一直在学习JavaScript,然后是Python,然后是C ++,但是现在我开始学习Java。
我做了一个非常简单的代码:
public class MyClass
{
public static void main(String[] args)
{
System.out.println(1 + 1 / 2);
}
}
这是错误的!返回1。
我尝试了另一种方式(如果有区别的话:):
double x = 1 + 1 / 2;
System.out.println(x);
没有成功。
让我们尝试另一种方式!
double x = 1 + Math.pow(2, -1);
System.out.println(x);
现在它正在工作!
好吧,我知道了,但是为什么这实际上没有奏效?我在做什么错?
谢谢你!