Cover by Christian Nagel, Daniel Kemper, Morgan Skinner, Jon Reid, Jacob Vibe Hammer, Karli Watson

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

A

Exercise Solutions

There are no exercises in Chapters 1 and 2.

CHAPTER 3 SOLUTIONS

Exercise 1

super.smashing.great

Exercise 2

b), as it starts with a number, and e), as it contains a full stop.

Exercise 3

No, there is no theoretical limit to the size of a string that may be contained in a string variable.

Exercise 4

The * and / operators have the highest precedence here, followed by +, <<, and finally +=. The precedence in the exercise can be illustrated using parentheses as follows:

resultVar += (((var1 * var2) + var3) << (var4 / var5));

Exercise 5

static void Main(string[] args)
{
   int firstNumber, secondNumber, thirdNumber, fourthNumber;
   Console.WriteLine("Give me a number:");
   firstNumber = Convert.ToInt32(Console.ReadLine());
   Console.WriteLine("Give me another number:");
   secondNumber = Convert.ToInt32(Console.ReadLine());
   Console.WriteLine("Give me another number:");
   thirdNumber = Convert.ToInt32(Console.ReadLine());
   Console.WriteLine("Give me another number:");
   fourthNumber = Convert.ToInt32(Console.ReadLine());
   Console.WriteLine("The product of {0}, {1}, {2}, and {3} is {4}.",
                 firstNumber, secondNumber, thirdNumber, fourthNumber,
                 firstNumber * secondNumber * thirdNumber * fourthNumber);
}

Note that Convert.ToInt32() is used here, which isn’t covered in the chapter.

CHAPTER 4 SOLUTIONS

Exercise 1

(var1 > 10) ^ (var2 > 10)
[AU: wrong sign]

Exercise 2

static void Main(string[] args) { bool numbersOK = false; double var1, var2; var1 = 0; var2 = 0; while (!numbersOK) ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required