Ask Question
11 August, 09:10

1. which of the following expressions evaluates multiplication first addition second and multiplication third A. 2*3+4*5

B. (2*3) + (4*5)

C. 2 * (3+4) * 5

D. 2 * (3+4*5)

2. After the following two statements, what is the value of j?

int i=10;

int j=10*i++;

A. 100

B. 101

C. 110

D. 111

3. Consider the following code.

int x=1;

int y=2;

System. out. println ("The sum of x and y is" + x+y+".");

What would be the result of the last statement?

A. It would display the text, "the sum of x and y is 3."

B. It would display the text, "the sum of x and y is 12."

C. It would display a very large number, something similar to 442152118.

D. The statement would cause a compilation error.

(Note: This is for Java programming)

+2
Answers (1)
  1. 11 August, 11:58
    0
    1. D. 2 * (3 + 4*5)

    2. A. 100

    3. B. It would display the text, "the sum of x and y is 12."

    Explanation:

    1.

    Mathematical expressions are evaluated according to operator preference. The operator preference goes like as follows:

    First expression under brackets are evaluated Then multiplication or division operator Then addition or subtraction operator.

    Thus in option D first 4*5 will be evaluated i. e. multiplication, after that 3 + 20 will be evaluated i. e. addition and finally 2*23 will be evaluated i. e. multiplication. Hence correct option is D.

    2.

    The execution of given statements will be as follows:

    First int i = 10; will get executed which will set value of i as 10. Then j = 10*i++; will get executed. In this statement first original value of i will get multiplied with 10. The result of multiplication will get stored in j. And after that i will get increment by 1.

    This is due to the use of post increment. In post increment the value of operator is incremented after the expression evaluation is complete.

    Thus final value of j after execution of both statements will be 10 * 10 = 100. Hence correct option is A.

    3.

    The first two statement of code segment are used to assign the value of 1 and 2 to x and y respectively. The statement System. out. println (); function in Java is used to provide output on console.

    The last statement will result in following output:

    The sum of x and y is12.

    Inside println () function any content within double inverted commas ("") is present as it is on console. The part + x+y + will be evaluated as 12 i. e. value of y written next to value of x.

    In case it was written as + (x+y) +, it would have been evaluated as 3 i. e. value of x + value of y.

    Hence the correct option is B.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “1. which of the following expressions evaluates multiplication first addition second and multiplication third A. 2*3+4*5 B. (2*3) + (4*5) ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers