Q. What will be the output?

Code:
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) 4.2 4.225D.2 4.225
πŸ’¬ Discuss
βœ… Correct Answer: (B) 2 2.5
Explanation: 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.)
Explanation by: Sandhya Thakur
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.)

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
112
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Sandhya Thakur
Publisher
πŸ“ˆ
87%
Success Rate