Computer Applications
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
Java Operators
23 Likes
Answer
x = 0; y = 0
Reason — Prefix decrement operator first decrements and then uses the value. Thus, the value of x will be decremented first (making x = 0) and then the value will be assigned to y (making y = 0).
Answered By
14 Likes
Related Questions
Which of the following might make the Java compiler report a syntax error in a particular line of a program?
- The program is typed in the wrong font.
- The line contains a comma(,) instead of a dot(.).
- It is caused by Java runtime.
- Program takes too long to complete.
A class is :
- an object factory
- a blueprint to create objects
- a specification for objects
- All of the above
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
Parameters in method definition are called
- actual parameters
- formal parameters
- informal parameters
- void parameters