Examveda
Examveda

What will be the output?
public class Test{
      public static void main(String args[]){
            int a = 42;
            double b = 42.25;
            System.out.print((a%10)+" "+(b%10));
      }
}

A. 42 42.5

B. 2 2.5

C. 4.2 4.225

D. 2 4.225

E. Compilation Error

Answer: Option B

Solution(By Examveda Team)

The modulus operator, % returns the remainder of a division operation. It can be applied on floating-point types as well as integer types. (This differs from C/C++, in which the % can only be applied on integer types.)


This Question Belongs to Java Program >> Operators

Join The Discussion

Comments ( 4 )

  1. Ibrahim Khan
    Ibrahim Khan :
    4 years ago

    Output will be 2,2.25

  2. K Lakshmi
    K Lakshmi :
    5 years ago

    its 22.25 ...

  3. Anonymous XYZ
    Anonymous XYZ :
    6 years ago

    it must be 2.25

  4. Shubham Asati
    Shubham Asati :
    7 years ago

    why % operator on double gives 2.5 not 2.25

Related Questions on Operators