[英]HTTP parser: scraping single page application: many GETs, how to find out when the page ends
[英]How to find out if a number ends in .5 or .0
我只是想知道你們是否可以幫助我解決問題?
double num = 2.0
if(num%1 != 0)
{
System.out.println("hi");
}
else if(num%.5 != 0)
{
System.out.println("hi there");
}
基本上,我想確保用戶輸入的數字以.0或.5結尾。但是我很難弄清楚。 上面的“解決方案”是我想出的,但似乎沒有用。 任何指針嗎?對於編程而言,它相對較新,因此將不勝感激。
%
運算符適用於浮點類型float
和double
以及Java中的整數類型。 以“ .0”或“ .5”結尾的任何數字都可以被0.5
整除。
if (num % 0.5 == 0)
{
System.out.println("Ends in .0 or .5!");
}
嘗試這個
if (num - Math.rint(num) == 0) {
System.out.println("hi");
} else if (Math.abs(num - Math.rint(num)) == 0.5) {
System.out.println("hi there");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.