Given the code fragment:



And given the requirements:

If the value of the qty variable is greater than or equal to 90, discount = 0.5
If the value of the qty variable is between 80 and 90, discount = 0.2

Which two code fragments can be independently placed at line n1 to meet the requirements?

A.

B.

C.

D.

E.

題解

選項A,程式邏輯符合題義。

選項B,qty若大於等於90,那它一定會大於80,因此第7行程式沒有作用,會被第8行的結果覆蓋。

選項C,程式邏輯符合題義。

選項D,qry若介於80到90之間,discount會在第二個if結構中,數值被改成0。

選項E,qty若大於等於90,那它一定會大於80,因此第二個三元條件運算子條件永遠不會成立。