Computer Applications
What will be the output of the following code?
int num = 10;
if (num < 20)
System.out.print(num++);
else
System.out.print(--num);
Java Conditional Stmts
3 Likes
Answer
Output
10
Explanation
Since the condition (num < 20) is true, the if block is executed. Postfix operator first uses the value and then increments the value, so the value of num is first printed (10) and then incremented.
Answered By
3 Likes
Related Questions
Find the value of
++a * (a++ + 5) + 3 * --a
, if a = 12.State the type of errors, if any in the following statements.
(a)
switch (x < 2)
(b)
int a = 100, b = 0; System.out.println (a / b);
Find the output of the given code.
int a, b = 100; for (a = 10; a <= 12; a++) { b += a; } System.out.print("a:" + a + " " + "b:" + b);
The following code has some error(s). Identify the errors and write the corrected code.
Int x = 4, y = 8; { y = y + (x++) } while (x <= 10) System.out.println(y);