Home » JAVA Programming » Basic Operators » Question
  1. What is the output of this program?

    public class Modulus_Example
    {
    public static void main(String args[])
    {
    double p = 10.34;
    int q = 20;
    p = p % 15;
    q = q % 20;
    System.out.println(p + " " + q);
    }
    }
    1. 10 0.0
    2. 11 10.00
    3. 10.22 10
    4. 10.34 0
    5. 2 10.21
Correct Option: D

Modulus operator returns the remainder of a division operation on the operand. p = p % 15 returns 10.34 % 15 i:e 10.34 Similarly q = q % 20 returns 0.
output: 10.34 0



Your comments will be displayed only after manual approval.