Question
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);
}
}
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);
}
}
Answer: Option C
Was this answer helpful ?
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 ?
More Questions on This Topic :
Question 2.
Which of these statements are incorrect?
....
Question 3.
Which of these statements are incorrect?
....
Question 6.
Which of these statements are incorrect?
....
Submit Solution