Question
class Output {
public static void main(String args[])
{
int x , y;
x = 10;
x++;
--x;
y = x++;
System.out.println(x + " " + y);
}
}
What is the output of this program?
class Output {
public static void main(String args[])
{
int x , y;
x = 10;
x++;
--x;
y = x++;
System.out.println(x + " " + y);
}
}
Answer: Option C
Was this answer helpful ?
x is initialized to 10 then increased by 1 by ++ operator making it 11. x
is again decreased by -
operator making it 10, next x is incremented by
post increment and intialized to y, here the value
of x obtained before
increment operator is executed, so value of y is 10 and value of x is
11.
output:
$ javac Output.java
$ java Output
11 10
Was this answer helpful ?
More Questions on This Topic :
Question 10.
What is the output of this program?
class Modul....
Submit Solution