Test your knowledge and understanding by answering some questions, get some hands-on practice, and explore with deeper research into this chapter's topics.
Answer the following questions:
int
variable by 0
?double
variable by 0
?int
variable, that is, set it to a value beyond its range?x = y++;
and x = ++y;
?break
, continue
, and return
when used inside a loop statement?for
statement and which of them are required?=
and ==
operators?for ( ; true; ) ;
What will happen if this code executes?
int max = 500; for (byte i = 0; i < max; i++) { WriteLine(i); }
Add a new console application named Ch03_Exercise02
and enter the preceding code. Run the console application and view the output. What happens?
What code could you add (don't change any of the preceding code) to warn us about the problem?
FizzBuzz is a group word game for children to teach them about division. Players take turns to count incrementally, replacing any number divisible by three with the word "fizz", any number divisible by five with the word "buzz", and any number divisible by both with "fizzbuzz".
Some interviewers give applicants simple FizzBuzz-style problems to solve during interviews. Most good programmers should be able to write out on paper or whiteboard a program to output a simulated FizzBuzz game in under a couple of minutes.
Want to know something worrisome? Many computer science graduates can't. You can even find senior programmers who take more than 10-15 minutes to write a solution.
Reginald Braithwaite
"199 out of 200 applicants for every programming job can't write code at all. I repeat: they can't write any code whatsoever."
This quote is taken from http://blog.codinghorror.com/why-cant-programmers-program/.
Refer to the following link for more information:
http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/
Create a console application named Ch03_Exercise03
that outputs a simulated FizzBuzz game counting up to 100. The output should look something like this:
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17,
Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32,
Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47,
Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62,
Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77,
Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92,
Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz
Create a console application named Ch03_Exercise04
that asks the user for two numbers in the range 0-255 and then divides the first number by the second:
Enter a number between 0 and 255: 100 Enter another number between 0 and 255: 8 100 divided by 8 is 12
Write exception handlers to catch any thrown errors:
Enter a number between 0 and 255: apples Enter another number between 0 and 255: bananas FormatException: Input string was not in a correct format.
Use the following links to read in more detail about the topics covered in this chapter:
3.145.8.8