Sample 1303 Midterm (Fall 2007)
- Write a snippet of code that asks the user for their name and prints out
"Hello X" where X is their name.
- What does the following code do?
for(int i=0; i < 3000; i += 3)
{
Console.WriteLine(i);
}
- Write a snippet of code that reads in four numbers from the user and
displays the smallest of the four numbers.
- Describe the difference between the WHILE, FOR, and DO-WHILE loops.
When is it appropriate to use each?
- Describe the similarities between the WHILE, FOR, and DO-WHILE loops.
- What does the following code do?
int i = 4;
int j = 10;
if ((i < 7) && (j < 10))
{
if (i + j < 20)
Console.WriteLine("A");
else
Console.WriteLine("B");
}
else
{
if (i + j < 20)
Console.WriteLine("C");
else
Console.WriteLine("D");
}
- Write a code snippet that repeatedly prompts the user to type "QUIT" and
reads in a string from the user until the user types "QUIT". You must
use a do-while loop in your solution.
- Describe the intent/purpose of methods and the use of methods in a
program.