Test Your Knowledge: Exercises
Exercise 5-1. Create a program that counts from 1 to 10 three times, using the while
, do…while
, and for
statements, and outputs the results to the screen.
Exercise 5-2. Create a program that prompts a user for input, accepts an integer, then evaluates whether that input is zero, odd or even, a multiple of 10, or too large (more than 100) by using multiple levels of if
statements.
Exercise 5-3. Rewrite the program from Exercise 5-2 to do the same work with a switch
statement.
Exercise 5-4. Create a program that initializes a variable i
at 0 and counts up, and initializes a second variable j
at 25 and counts down. Use a single for
loop to increment i
and decrement j
simultaneously, and output the values of i
and j
at each iteration of the loop. When i
is greater than j
, end the loop and print out the message “Crossed over!”
Get Learning C# 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.