how to use Java modulus operator (%). - Java Language Basics

Java examples for Language Basics:Operator

Description

how to use Java modulus operator (%).

Demo Code


public class Main {
        public static void main(String[] args) {
               /*from  w  w  w  .  j  a  v a2 s. c  om*/
                System.out.println("Java Modulus Operator example");
                 
                int i = 50;
                double d = 32;
                 
                System.out.println("i mod 10 = " + i%10);
                System.out.println("d mod 10 = " + d%10);
        }
}

Result


Related Tutorials