Here is a Java Program to Demonstrate the % operator
Output of Above Java Program
x mod 10 = 2
y mod 10 = 2.25
class Modulus { public static void main(String args[]) { int x = 42; double y = 42.25; System.out.println("x mod 10 = " + x % 10); System.out.println("y mod 10 = " + y % 10); } }
Output of Above Java Program
x mod 10 = 2
y mod 10 = 2.25