Answer 01

What is the final value of sum after the following code executes?

    void main() 
    {
        int a = 5;
        int b = 3;
        int sum = a + b;
        sum = sum * 2;
        sum = sum - a;
        sum = sum + b;
    }
  • (A) 8

  • (B) 12

  • (C) 14 [*]

  • (D) 16

Answer 02

What is the final value of result after the following code executes?

    void main() 
    {
        int x = 8;
        int y = 4;
        int result = x + y;
        if (result > 10) 
        {
            result = result - x;
        } 
        else
        {
            result = result + y;
        }
        result = result * 2;
    }
  • (A) 16

  • (B) 8 [*]

  • (C) 12

  • (D) 20

Answer 03

What is the final value of z after the following code executes?

    void main() 
    {
        int x = 10;
        int y = 2;
        int z = x - y;
        z = z + x / y;
        z = z - y * 2;
        z = z + (x % y);
    }
  • (A) 9 [*]

  • (B) 12

  • (C) 13

  • (D) 14

Answer 04

What will be the final value of a after the following code executes?

    void main() 
    {
        int a = 7;
        int b = 3;
        a = a + b;
        if (a % 2 == 0) 
        {
            a = a * 2;
        } 
        else 
        {
            a = a - b;
        }
        a = a + (b * 3);
    }
  • (A) 22

  • (B) 28

  • (C) 26

  • (D) 29 [*]

Answer 05

What is the final value of n after the following code executes?

    void main() 
    {
        int n = 6;
        int m = 4;
        n = n + m;
        if (n > 10) 
        {
            n = n - 5;
        } 
        else 
        {
            n = n + 3;
        }
        n = n * 2;
        n = n - m;
    }
  • (A) 18
  • (B) 22 [*]

  • (C) 20

  • (D) 14

 

Last modified: Monday, 28 October 2024, 8:12 AM