Self-Review Exercises

  1. 3.1 Fill in the blanks in each of the following statements:

    1. A(n)                 begins the body of every method, and a(n)                 ends the body of every method.

    2. Most statements end with a(n)                .

    3. The                 statement is used to make decisions.

    4.                 begins a single-line comment.

    5.                ,                 and                 are called whitespace. Newline characters are also considered whitespace.

    6.                 are reserved for use by C#.

    7. C# apps begin execution at method                .

    8. Methods                 and                 display information in the console window.

    9.                 enables you to insert values directly into a string literal.

  2. 3.2 State whether each of the following is true or false. If false, explain why.

    1. Comments cause the computer to display the text after the // on the screen when the app executes.

    2. C# considers the variables number and NuMbEr to be identical.

    3. The remainder operator (%) can be used only with integer operands.

    4. The arithmetic operators *, /, %, + and - all have the same level of precedence.

    5. An interpolated string must begin with a $ before the string literal.

  3. 3.3 Write statements to accomplish each of the following tasks:

    1. Declare variables c, thisIsAVariable, q76354 and number to be of type int.

    2. Prompt the user to enter an integer.

    3. Input an integer and assign the result to int variable value.

    4. If the variable number is not equal to 7, display "The variable number is not equal to 7".

    5. Display "This is a C# app" on one line in the console window.

    6. Display "This is a C# app" on two lines in the console window. The first line should end with C#. Use method Console.WriteLine.

    7. Write a statement that uses string interpolation to display the sum of the variables x and y. Assume variables x and y of type int exist and already have values.

  4. 3.4 Identify and correct the errors in each of the following statements:

    1. 
      if (c < 7);
      {
         Console.WriteLine("c is less than 7");
      }
      
    2. 
      if (c => 7)
      {
         Console.WriteLine("c is equal to or greater than 7");
      }
      
  5. 3.5 Write declarations, statements or comments that accomplish each of the following tasks:

    1. State that an app will calculate the product of three integers.

    2. Declare the variables x, y, z and result to be of type int.

    3. Prompt the user to enter the first integer.

    4. Read the first integer from the user and store it in the variable x.

    5. Prompt the user to enter the second integer.

    6. Read the second integer from the user and store it in the variable y.

    7. Prompt the user to enter the third integer.

    8. Read the third integer from the user and store it in the variable z.

    9. Compute the product of the three integers contained in variables x, y and z, and assign the result to the variable result.

    10. Display the message "Product is", followed by the value of the variable result—use string interpolation.

  6. 3.6 Using the statements you wrote in Exercise 3.5, write a complete app that calculates and displays the product of three integers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset