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);
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..?
Thanks for any help,
Kind Regards
Get the remainder using % operator. Expressions used in program to calculate quotient and remainder: quotient = dividend / divisor; remainder = dividend % divisor; Note: The program will throw an ArithmeticException: / by zero when divided by 0.
In integer division and modulus, the dividend is divided by the divisor into an integer quotient and a remainder. The integer quotient operation is referred to as integer division, and the integer remainder operation is the modulus.
int remainder = a % b; will sort you. The remainder operator returns the remainder of the division. Note that the remainder operator is also called the modulo operator.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With