Computer Applications
Consider the following code snippet:
float x = 8.25F;
int y;
y = (int)x;
What are the values of x and y?
- x = 8.25, y = 8
- x = 8.0, y = 8.0
- x = 8, y = 8.25
- x = 8, y = 8
Answer
x = 8.25, y = 8
Reason — float data type can store numbers with decimal and int data type stores signed/unsigned integer values. So, x = 8.25. Then, the user is declaring an int variable y and type casting the float value x to an int and assigning it to y.
When we cast x to an int, the fractional part is truncated and the int value (8) is stored in y. Thus, y = 8.
Related Questions
A class is :
- an object factory
- a blueprint to create objects
- a specification for objects
- All of the above
Assume x = 1 with the following code snippet:
int y = --x;Which one of the following is true?
- x = 1, y = 1
- x = 0; y = 0
- x = 1; y = 0
- x = 0; y = 1
Parameters in method definition are called
- actual parameters
- formal parameters
- informal parameters
- void parameters
Give the output of
Math.ceil(-0.6)- -1.6
- -1.5
- -1.0
- -0.0