Scanner s = new Scanner(System.in);
System.out.println("请输入:");
double x = s.nextDouble();
System.out.println(x);
if(Math.abs(x) % 180 == 90){
System.out.println("error");
}
else{
float y = (float)Math.tan(x*Math.PI/180);
System.out.println(y);
}为什么当我输入180时,得到的结果不是0。 求解释。JavaMath
该怎么改。
但是可能因为java计算double时不精确,得到的数字总是一个无限趋于0的数,比如45度(Math.PI/4)运算结果是0.99999999,而不是1,Java菜鸟,不会解决这个问题了