C# Unit 4

  1. What is the output of the following code segment?

    int a = 3, b = 4;
    if (a == b)
        Write("X");
        WriteLine("Y");




    C. Y
  2. What is the output of the following code segment?

    int a = 3, b = 4;
    if (a < b)
    {
       Write("Y");
       WriteLine("Z");
    }




    C. YZ
  3. What is the output of the following code segment?

    int a = 3, b = 4;
    if (a > b)
       Write("Up");
    else
        WriteLine("Down");




    A. Down
  4. If the following code segment compiles correctly, what do you know about the variable x?

    if(x) WriteLine("OK");




    D. x is a Boolean variable
  5. What is the output of the following code segment?

    int c = 6, d = 12;
    if(c > d);
       Write("Green");
       WriteLine("Yellow");




    B. GreenYellow
  6. What is the output of the following code segment?

    int c = 6, d =12;
    if(c > d)
        if(c > 8)
           Write("Blue");
        else
           Write("Red");
    else
       Write("Green");




    D. Red
  7. What is the output of the following code segment?

    int e = 5, f = 10;
    if (e < f && f < 0)
       Write("Red");
    else
       Write("Orange");




    D. Orange
  8. What is the output of the following code segment?

    int e = 5, f = 10;
    if (e < f || f < 0)
        Write("Purple");
    else
       Write("Gold");




    B. Purple
  9. Which of the following expressions is equivalent to the following code segment?

    if (g > h)
        if (g < k)
            Write("Brown");

    A. if (g > h && g < k)
          Write("Brown");
    B. if (g > h && < k)
           Write("Brown");
    C. if (g > h || g < k)
            Write("Brown");
    D. two of these
    • A. if (g > h && g < k)
    •       Write("Brown");
  10. Which of the following expressions assigns true to a Boolean variable named isIDValid when idNumber is both greater than 1000 and less than or equal to 9999, or else is equal to 123456?




    A. two of these
  11. Which of the following expressions is equivalent to a || b && c || d?




    C. a || (b && c) || d
  12. How many case labels would a switch statement require to be equivalent to the following if statement?

    if(v == 1)
      WriteLine("one");
    else
      WriteLine("two");




    B. one
  13. In C#, falling through a switch case is most often prevented by using the ______ statement.




    D. break
  14. If the test expression in a switch does not match any of the case values, and there is no default value, then ________.




    C. the program continues with the next executable statement
  15. Which of the following is equivalent to the following statement?

    if(m == 0)
       d = 0;
    else
       d = 1;




    D. d = (m == 0) ? 0 : 1;
  16. Which of the following C# expressions is equivalent to a < b && b < c?




    C. !(b <= a) && b < c
  17. Which of the following C# expressions means, "If itemNumber is not 8 or 9, add TAX to price"?
    A. if (itemNumber != 8 || itemNumber != 9)
       
        price = price + TAX;
    B. if (itemNumber != 8 && itemNumber != 9)

        price = price + TAX;
    C. if (itemNumber != 8 && != 9)

        price = price + TAX;
    D. two of these
    B. if (itemNumber != 8 && itemNumber != 9)

        price = price + TAX;
  18. Which of the following C# expressions means, "If itemNumber is 1 or 2 and quantity is 12 or more, add TAX to price"?

    A. if (itemNumber = 1 || itemNumber = 2 && quantity >= 12)

        price = price + TAX;
    B. if (itemNumber == 1 || itemNumber == 2 || quantity >= 12)

        price = price + TAX;
    C. if (itemNumber == 1 && itemNumber == 2 && quantity >=12)

        price = price + TAX;
    D. none of these
    D. none of these
  19. Which of the following C# expressions means, "If itemNumber is 5 and zone is 1 or 3, add TAX to price"?

    A. if (itemNumber == 5 && zone == 1 || zone == 3)
        
        price = price + TAX;
    B. if (itemNumber == 5 && (zone == 1 || zone == 3))

        price = price + TAX;
    C. if (itemNumber == 5 && (zone ==1 || 3))
     
        price = price + TAX;
    D. two of these
    B. if (itemNumber == 5 && (zone == 1 || zone == 3))

        price = price + TAX;
  20. Which of the following C# expressions results in TAX being added to price if the integer itemNumber is not 100?

    A. if (itemNumber != 100) 

        price = price + TAX;
    B. if (!(itemNumber == 100))

        price = price + TAX;
    C. if (itemNumber <100 || itemNumber > 100)

        price = price + TAX;
    D. all of these
    D. all of these
Author
jdavis123
ID
358168
Card Set
C# Unit 4
Description
Updated