Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

consider the following: int a = 5; int b = 2; system.out.println(a + 2 …

Question

consider the following: int a = 5; int b = 2; system.out.println(a + 2 * b--); system.out.println(b); which of the following statements is true?

Explanation:

Step1: Evaluate the first print statement

In Java, for System.out.println(a + 2 b--);, first, we calculate the expression a + 2 b--. Here, a = 5 and b = 2. The post - decrement operator b-- first uses the value of b in the expression and then decrements it. So, a+2 b = 5+22=5 + 4=9. After this operation, b becomes 1.

Step2: Evaluate the second print statement

The second System.out.println(b); will print the value of b which is 1 after the post - decrement operation in the previous step. So the output will be 91.

Answer:

91