3.1 Fill in the blanks in each of the following statements:
A(n) begins the body of every method, and a(n) ends the body of every method.
Most statements end with a(n) .
The statement is used to make decisions.
begins a single-line comment.
, and are called whitespace. Newline characters are also considered whitespace.
are reserved for use by C#.
C# apps begin execution at method .
Methods and display information in the console window.
enables you to insert values directly into a string literal.
3.2 State whether each of the following is true or false. If false, explain why.
Comments cause the computer to display the text after the //
on the screen when the app executes.
C# considers the variables number
and NuMbEr
to be identical.
The remainder operator (%
) can be used only with integer operands.
The arithmetic operators *
, /
, %
, +
and -
all have the same level of precedence.
An interpolated string must begin with a $
before the string literal.
3.3 Write statements to accomplish each of the following tasks:
Declare variables c
, thisIsAVariable
, q76354
and number
to be of type int
.
Prompt the user to enter an integer.
Input an integer and assign the result to int
variable value
.
If the variable number
is not equal to 7
, display "The
variable
number
is
not
equal
to
7"
.
Display "This is a C# app"
on one line in the console window.
Display "This
is
a
C#
app"
on two lines in the console window. The first line should end with C#
. Use method Console.WriteLine
.
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.
3.4 Identify and correct the errors in each of the following statements:
if (c < 7);
{
Console.WriteLine("c is less than 7");
}
if (c => 7)
{
Console.WriteLine("c is equal to or greater than 7");
}
3.5 Write declarations, statements or comments that accomplish each of the following tasks:
State that an app will calculate the product of three integers.
Declare the variables x
, y
, z
and result
to be of type int
.
Prompt the user to enter the first integer.
Read the first integer from the user and store it in the variable x
.
Prompt the user to enter the second integer.
Read the second integer from the user and store it in the variable y
.
Prompt the user to enter the third integer.
Read the third integer from the user and store it in the variable z
.
Compute the product of the three integers contained in variables x
, y
and z
, and assign the result to the variable result
.
Display the message "Product
is"
, followed by the value of the variable result
—use string
interpolation.
3.6 Using the statements you wrote in Exercise 3.5, write a complete app that calculates and displays the product of three integers.