Answer 01

[1 mark] What is the final value of result after the following code executes?

void main() 
{
	int x = 4;
	int y = 7;
	int result = x * y;
	result = result - x;
	result = result + y;
}
  • (A) 25

  • (B) 28

  • (C) 31 [*]

  • (D) 36

Answer 02

[1 mark] What is the final value of result after the following code executes?

	void main() 
	{
		int a = 6;
		int b = 3;
		int result = a + b;
		if (result > 8)
		{
			result = result * 2;
		}
		else
		{
			result = result + 5;
		}
	}
  • (A) 9

  • (B) 11

  • (C) 14

  • (D) 18 [*]

Answer 03

[1 mark] What is the final value of result after the following code executes?

	void main() 
	{
		int result = 0;
		for (int i = 1; i <= 4; i++)
		{
			result = result + i;
		}
	}
  • (A) 4

  • (B) 6

  • (C) 10 [*]

  • (D) 16

Answer 04

[2 marks] What is the final value of result after the following code executes?

	void main() 
	{
		int result = 0;
		for (int i = 1; i <= 5; i++)
		{
			if (i % 2 == 0)
			{
				result = result + i;
			}
		}
	}
  • (A) 4

  • (B) 6 [*]

  • (C) 8

  • (D) 10

Answer 05

[2 marks] What is the final value of result after the following code executes?

	void main() 
	{
		int result = 0;
		for (int i = 1; i <= 3; i++)
		{
			for (int j = 1; j <= 2; j++)
			{
				result = result + i * j;
			}
		}
	}
  • (A) 9

  • (B) 12

  • (C) 15

  • (D) 18 [*]

Answer 06

[3 marks] What is the final value of result after the following code executes?

	void main() 
	{
		int result = 0;
		for (int i = 1; i <= 3; i++)
		{
			for (int j = 1; j <= 3; j++)
			{
				if ((i + j) % 2 == 0)
				{
					result = result + i * j;
				}
			}
		}
	}
  • (A) 10

  • (B) 12

  • (C) 18

  • (D) 20 [*]

Last modified: Tuesday, 5 November 2024, 10:30 PM