Modulus Operator Example : Modulus « Language Basics « Java






Modulus Operator Example

 


public class Main {

  public static void main(String[] args) {
    int i = 5;
    double d = 2;

    System.out.println("i mod 10 = " + i % 10);
    System.out.println("d mod 10 = " + d % 10);
  }
}
/*
i mod 10 = 5
d mod 10 = 2.0
*/

   
  








Related examples in the same category

1.Detect even/odd number with the modulus operator.