What is displayed when the following is executed

What is displayed when the following is executed;java

double d1=-0.5;
System.out.println("Ceil d1="+Math.ceil(d1));
System.out.println("floor d1="+Math.floor(d1));

 

  • Ceil d1=-0.0
    floor d1=-1.0
  • Ceil d1=0.0
    floor d1=-1.0
  • Ceil d1=-0.0
    floor d1=-0.0
  • Ceil d1=0.0
    floor d1=0.0
  • Ceil d1=0
    floor d1=-1

Acode

  • ceil:大於等於 x,而且與它最接近的整數。
  • floor:小於等於 x,且與 x 最接近的整數。
  • 若是參數小於0且大於-1.0,結果爲 -0
相關文章
相關標籤/搜索