What is the value after evaluating this expression in Java?
2 + 6 / 3 * 5 * 2 - 3

0 17.0 19 -1.0 Expressions are evaluated following the rules of PEMDAS. So first left division, 6/3 is evaluated and then all the right side multiplcations and finally addition and subtraction are evaluated.

Study the below expression
d = d+3;
This can be replaced by which shorthand notation?

d += 3 d =+ 3 Cannot be replace with anything

You want to find if a given number 'a' is even or not. Which expression would you use?

a / 2 == 0 a % 2 == 0 a * 2 Modulo operator % gives you the remainder. If the remainder is 0 after using modulo operator with 2, then it is an even number. If the remainder is 1 then it is odd.

You want to declare a variable named 'months' and store the value of number of months in a year, 12 and it never changes. Which data type will you choose for this variable?

int byte short double byte uses 8 bits and can hold upto a maximum value of 127. Since we are storing a value of 12, we can use byte. All the other options use more bits and hence occupies more memory to store this small number, which is not efficient.

A comment line is executed by Java compiler. True or False

False True

results matching ""

    No results matching ""