Programming C#
  1. Consider the following code segment.

    int x;
    x = 53;
    if (x > 10){
        Console.Write(“A”) ;
    }
    if (x > 30){
        Console.Write(“B”) ;
    }
    else if (x > 40){
        Console.Write(“C”) ;
    }
    if (x > 50){
        Console.Write (“D”) ;
    }
    if (x > 70){
        Console.Write (“E”) ;
    }
    

    What is output when the code is executed?

    1. A
    2. D
    3. ABD
    4. ABCD
    5. ABCDE
  2. In the following code segment, you may assume that a, b, and n are all type int.

    if (a != b && n / (a - b) > 90){
    	/* statement 1 */
    }else{
    	/* statement 2 */
    }
    /* statement 3 */

    What will happen if a == b is false?

    1. /* statement 1 */ will be executed.
    2. /* statement 2 */ will be executed.
    3. Either /* statement 1 */ or /* statement 2 */ will be executed.
    4. A compile-time error will occur.
    5. An exception will be thrown.
  3. Consider the following code segment. Assume num is a properly declared and initialized int variable.

    if (num > 0){
        if (num % 2 == 0){
            Console.WriteLine("A");
        }else{
            Console.WriteLine("B");
        }
    }

    Which of the following best describes the result of executing the code segment?

    1. When num is a negative odd integer, "B" is printed; otherwise, "A" is printed.
    2. When num is a negative even integer, "B" is printed; otherwise, nothing is printed.
    3. When num is a positive even integer, "A" is printed; otherwise, "B" is printed.
    4. When num is a positive even integer, "A" is printed; when num is a positive odd integer, "B" is printed; otherwise, nothing is printed.
    5. When num is a positive odd integer, "A" is printed; when num is a positive even integer, "B" is printed; otherwise, nothing is printed.