java中的数学-什么是";%&引用;做

java中的数学-什么是";%&引用;做,java,c++,Java,C++,我知道代码是将毫秒转换为秒、分和小时,但我不明白“%”的作用。。。 整数秒=(整数)(毫秒/1000)%60 有人能解释一下吗 我可以在C++中做同样的动作吗? 谢谢 milliseconds = ((System.currentTimeMillis()) - (startTime)); int seconds = (int) (milliseconds / 1000) % 60 ; int minutes = (int)

我知道代码是将毫秒转换为秒、分和小时,但我不明白“%”的作用。。。 整数秒=(整数)(毫秒/1000)%60

有人能解释一下吗

<>我可以在C++中做同样的动作吗? 谢谢

             milliseconds = ((System.currentTimeMillis()) - (startTime));
            int seconds = (int) (milliseconds / 1000) % 60 ;
            int minutes = (int) ((milliseconds / (1000*60)) % 60);
            int hours   = (int) ((milliseconds / (1000*60*60)) % 24);

%
是模数运算符。用于:

例如:10%3等于1。从视觉上看-

10 % 3
10 - 3 = 7    // Start by subtracting the right hand side of the % operator
7 - 3 = 4     // Continue subtraction on remainders
4 - 3 = 1
Now you can't subtract 3 from 4 without going negative so you stop.
You have 1 leftover as a remainder so that is your answer.
你可以把它想象成“为了让它能被右边的值平均整除,我必须减去左边的值多少?”


是的,实际上它和C++中表示模数的符号是一样的


在算术中,余数是一个整数除以另一个整数得到整数商(整数除法)后的“剩余”整数


“在计算中,模(有时称为模)运算可以找到一个数除以另一个数的余数。”

我在一些网站上也读到过。。但我还是不知道understand@Helena你知道余数是什么吗?@Helena:如果你把像
17
这样的整数除以
5
,结果是
3
,但是还有
2
,因为
17=5*3+2
。“rest”是余数,这就是
%
返回的结果。换句话说:
17/5-->3
17%5-->2
。如果你不明白模/余数是什么,我建议你读一本基础数学书,而不是问here@LưuVĩnhPhúc:我是荷兰人,我相信我的许多同胞可能知道余数或模的概念,但可能不知道英文术语“余数”或“模数”。在荷兰语中,它通常被称为“rest”,在其他一些语言中也是如此。
10 % 3
10 - 3 = 7    // Start by subtracting the right hand side of the % operator
7 - 3 = 4     // Continue subtraction on remainders
4 - 3 = 1
Now you can't subtract 3 from 4 without going negative so you stop.
You have 1 leftover as a remainder so that is your answer.