I’m trying to convert some JavaScript code into Java, but I do not know what the % character between two numeric variables does:
testvalue = somevalue%anothervalue;
What does this mean or what would the same statement be in Java?
I also have this in JavaScript:
if(somevalue%2 == 1){
}
What does %2 mean here?
It’s the modulus operator.
This returns “the first operand modulo the second operand”, which is the remainder when you substract (or add) as much of the second operand off/to of the first, to get as close as possible to 0.
Here’s an example: