3.1 a) left brace ({
), right brace (}
). b) semicolon (;
). c) if
. d) //
. e) Blank lines, space characters, tab characters. f) Keywords. g) Main
. h) Console.WriteLine
and Console.Write
. i) string
interpolation.
3.2 The answers to Self-Review Exercise 3.2 are as follows:
False. Comments do not cause any action to be performed when the app executes. They’re used to document apps and improve their readability.
False. C# is case sensitive, so these variables are distinct.
False. The remainder operator also can be used with noninteger operands in C#.
False. The operators *
, /
and %
are on the same level of precedence, and the operators +
and -
are on a lower level of precedence.
True.
3.3 The answers to Self-Review Exercise 3.3 are as follows:
int c;
int thisIsAVariable;
int q76354;
int number;
Console.Write("Enter an integer: ");
value = int.Parse(Console.ReadLine());
if (number != 7)
{
Console.WriteLine("The variable number is not equal to 7");
}
Console.WriteLine("This is a C# app");
Console.WriteLine("This is a C#
app");
Console.WriteLine($"The sum of {x} and {y} is {x + y}");
3.4 The answers to Self-Review Exercise 3.4 are as follows:
Error: Semicolon after the right parenthesis of the condition (c
<
7
) in the if
statement.
Correction: Remove the semicolon after the right parenthesis. [Note: With the semicolon, the output statement executes regardless of whether the condition in the if
is true.]
Error: The relational operator =>
is incorrect.
Correction: Change =>
to >=
.
3.5 The answers to Self-Review Exercise 3.5 are as follows:
// Calculating the product of three integers
int x;
int y;
int z;
int result;
Console.Write("Enter first integer: ");
x = int.Parse(Console.ReadLine());
Console.Write("Enter second integer: ");
y = int.Parse(Console.ReadLine());
Console.Write("Enter third integer: ");
z = int.Parse(Console.ReadLine());
result = x * y * z;
Console.WriteLine($"Product is {result}");
3.6 The solution to Self-Review Exercise 3.6 is as follows: