It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
大家好,我有这样的事情
例如两个整数:

int priceSell = 10;
int priceBuy = 5;


如何检查这些数字之间的范围不超过10%?

最佳答案

int priceSell = 10;
int priceBuy = 5;
if (Math.abs(priceSell-priceBuy)>(priceSell/10))
    System.out.println("the price isn't within 10%");
else
    System.out.println("the price is within 10%");


-不除以0

顺便说一句,这个答案可以确保买入价格在卖出价格的10%以内。另一个答案是要确保卖出价格在买入价格的10%以内。
是的,那很重要。 90在100的10%之内,但100不在90的10%之内。(100的10%范围是90-110.90的10%范围是81-99)

关于java - 如何检查两个数字的范围是否不超过10%(JAVA),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13210506/

10-12 19:19