Is there a way to calculate if an integer is congruent with the expression 17 modulo 5 in java. The expression could be any variation of the x modulo y. Any ideas on how to make a method to check for this?
Implementation of congruence in java
2.9k Views Asked by Lars Christensen At
3
You can use Java's remainder operator
%. Ifaandbare both positive,a % bequals thea mod b.However, the (mathematical) meaning of modulo is a bit different. If
bis positive,a % bhas the same sign aa. Thus-3 % 10 = -3, while-3 mod 10 = 7. To calculate the modulo, you can useor as a single expression: