Sunday, 3 January 2016

JAVA Program to demonstrate the Modulus Operator

Usage of Modulus Operator in JAVA


A program to display the modulus of Integer and Floating Point numbers



//A Java Program to demonstrate modulus operator

public class ModulusJava
{
    public static void main(String args[])
    {        
            int x=12;
            double y = 12.5;
            System.out.println("x mod 10 = " + x % 10);
            System.out.println("y mod 10 = " + y % 10);
   }
}

Output:


x mod 10 = 2
y mod 10 = 2.5

No comments :

Post a Comment