Sail E0 Webinar
Question


What is the output of this program?


class operators {
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
int var3;
var3 = ++ var2 * var1 / var2 + var2;
System.out.print(var3);
}
}
Options:
A .  10
B .  11
C .  12
D .  56
Answer: Option C

Operator ++ has the highest precedence than / , * and +. var2 is
incremented to 7 and then used

in expression, var3 = 7 * 5 / 7 + 7,
gives 12.
output:
$ javac operators.java
$ java operators
12



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers