Java OCA OCP Practice Question 624

Question

Consider the following code:

public class Main{ 
   public static void main (String [] args){ 
     int i = 1234567890; 
     float f = i; 
     System .out.println (i -  (int)f); 
    } 
} 

What will it print when run?

Select 1 option

  • A. It will print 0.
  • B. It will not print 0.
  • C. It will not compile.
  • D. It will throw an exception at runtime.
  • E. None of the above.


Correct Option is  : B

Note

Actually it prints -46.

This is because the information was lost during the conversion from type int to type float as values of type float are not precise to nine significant digits.




PreviousNext

Related