MCQs
Parentheses do not degrade the performance of the program. Adding
parentheses to reduce ambiguity
does not negatively affect your system.
The first two iterations of the for loop both x and y are incremented. On the third iteration
x is incremented, and for the first time becomes greater than 2. The short circuit or operator
|| keeps y from ever being incremented again and x is incremented twice on each of the last
three iterations.
In the first two iterations x is incremented once and y is not because of the short circuit &&
operator. In the third and forth iterations x and y are each incremented, and in the fifth iteration
x is doubly incremented and y is incremented.
None.
output:
$ javac leftshift_operator.java
$ java leftshift_operator
256 0
None.
output:
$ javac ternary_operator.java
$ java ternary_operator
3
The first two iterations of the for loop both x and y are incremented. On the third iteration
x is incremented, and for the first time becomes greater than 2. The short circuit or operator
|| keeps y from ever being incremented again and x is incremented twice on each of the last
three iterations.
Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32.
output:
$ javac increment.java
$ java increment
32
And operator produces 1 bit if both operand are 1. Or operator produces 1 bit if any bit of the two
operands in 1.
output:
$ javac bitwise_operator.java
$ java bitwise_operator
7 2
In the first two iterations x is incremented once and y is not because of the short circuit &&
operator. In the third and forth iterations x and y are each incremented, and in the fifth iteration
x is doubly incremented and y is incremented.
Modulus operator returns the remainder of a division operation on the
operand. a = a % 10 returns
25.64 % 10 i:e 5.640000000000001. Similarly b
= b % 10 returns 5.
output:
$ javac Modulus.java
$ java Modulus
5.640000000000001 5