Modulus operator %: obtain the remainder after a division : Arithmetic Operators « Operators « Java Tutorial






public class MainClass {

  public static void main(String[] argv) {
    int a = 3 % 2;
    int b = 11 % 3;
    int c = 7 % -3;

    System.out.println(a);
    System.out.println(b);
    System.out.println(c);
  }

}
1
2
1








3.4.Arithmetic Operators
3.4.1.Arithmetic Calculations
3.4.2.Arithmetic Operators
3.4.3.The Basic Arithmetic Operators
3.4.4.Demonstrates the mathematical operators
3.4.5.Modulus operator %: obtain the remainder after a division
3.4.6.Applying the modulus operator, %, to floating-point values