运算符: 如果(编号%24 == 0) { $ ... b $ b} %运算符除以它的第一个之后,计算剩余它的第二个操作数。所有的数字类型已预定义其余运营商 几乎是它返回一个除法的余数:25%4 = 1,因为25装配在24一次,你有1左右。当数字完全适合你会得到一个返回0,并在你的例子是你怎么知道,如果一个数字是24整除,否则返回值将大于0。 I'd like to put up a if function, that will see if the variable is dividable by 24, if it's then it does the function else not, same logic however, I want to see if the output is a perfect number, e.g if we do 24/24 that will get 1, that's a perfect number. If we do 25/24 then it'll get 1.041 which is not a perfect number, the next perfect number will come when it reaches 48 that will be 48/24 which will get 2 that's a perfect number. 解决方案 Use the Modulus operator:if (number % 24 == 0){ ...} The % operator computes the remainder after dividing its first operand by its second. All numeric types have predefined remainder operators.Pretty much it returns the remainder of a division: 25 % 4 = 1 because 25 fits in 24 once, and you have 1 left. When the number fits perfectly you will get a 0 returned, and in your example that is how you know if a number is divisible by 24, otherwise the returned value will be greater than 0. 这篇关于检查数字是整除24的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 07:50