问题描述
我一直在搜索有关此主题的信息,但我仍然听不懂,如果有人可以详细说明,我将非常感激.
I was searching around about this topic but I still don't get it, if someone can elaborate I would be very thankful.
我的任务是将两个变量除以整数除法.问题是,我不知道余数是什么,现在我做了类似的事情,这是我通过互联网搜索发现的:
My task is to divide two variables as integer division with remainder..The problem is, that I have no clue what a remainder is, for now I did something like that, this is what I found by searching through the internet:
int a;
int b;
int remainder = Math.Pow(a,2) % b;
System.out.println("a^2 / b = " + Math.Pow(a,2) / b);
System.out.println("remainder = " + remainder);
例如,如果我设置了(a = 43)和(b = 67)
if I for example set (a = 43) and (b = 67)
然后我会得到这个结果:
Then I will get this reslut:
a^2 / b = 27
remainder = 40
现在,由于我不知道剩下的是什么(这只是互联网的建议),我不知道这是否是正确的答案.?
Now since I have no idea what the remainder is (this is just a suggestion form the internet) I have no idea if this is the correct answer..?
感谢您的帮助,
亲切的问候
推荐答案
如果您正在寻找数学模运算,可以使用
If you are looking for the mathematical modulo operation you could use
int x = -22;
int y = 24;
System.out.println(Math.floorMod(x, y));
如果您对数学模数不感兴趣(仅余数),则可以使用
If you are not interested in the mathematical modulo (just the remainder) then you could use
int x = -22;
int y = 24;
System.out.println(x%y);
这篇关于Java剩余整数除法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!