Wednesday, June 3, 2009

statement

1. Listing cases consecutively with no statements between them enables the cases to perform the same set of statements.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




2. An expression containing operator || is true if either or both of its operands are true.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




3. The default label is required in the switch selection statement.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




4. Assume the integer variables sum and count have been declared. This code sums the odd integers between 1 and 99, inclusive, using a for statement.

sum = 0;
for ( count = 1; count <= 99; count += 2 )
sum += count;

A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




5. The integer after the comma (,) in a format item ( e.g., {0,4} ) indicates the field width of the displayed string.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




6. The expression ( x > y && a < b ) is true if either the expression x > y is true or the expression a < b is true.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




7. To test for a range of values in a switch statement, use a hyphen ( - ) between the start and end values of the range in a case label.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




8. The break statement is required in every case of a switch selection statement to exit the switch properly.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




9. Assume that the variable n has been declared, but not initialized. Which of these match the output of these C# statements?

n = 1;
while ( n < 10 )
Console.Write( n++ );

A) 0123456789
B) 012345678910
C) 123456789
D) 12345678910
E) None of these.

Points Earned: 1.0/1.0
Correct Answer(s): C




10. Match each of these code segments to the appropriate comment.
A. The code segment has valid syntax, but it has some other error.
B. The code segment has valid syntax and no logic errors.
C. Infinite loop.
D. Floating-point number is not allowed here.
E. The code segment has invalid syntax.
F. Missing break statement.


ABCDEF
float y;
for ( y = .1; y != 1.0; y += .1 )
Console.WriteLine( y );
ABCDEF
x = 1;
while (x <= 10);
{
x++;
}
ABCDEF
n = 1;
while ( n < 10 )
Console.WriteLine( n++ );
ABCDEF
int n;
n = 1;
switch ( n )
{
case 1:
Console.WriteLine( "The number is 1." );
case 2:
Console.WriteLine( "The number is 2." );
break;
default:
Console.WriteLine( "The number is not 1 or 2." );
break;
}
Points Earned: 4.0/4.0
Correct Answer(s): Infinite loop. :
x = 1;
while (x <= 10);
{
x++;
}, Floating-point number is not allowed here. :
float y;
for ( y = .1; y != 1.0; y += .1 )
Console.WriteLine( y );, Missing break statement. :
int n;
n = 1;
switch ( n )
{
case 1:
Console.WriteLine( "The number is 1." );
case 2:
Console.WriteLine( "The number is 2." );
break;
default:
Console.WriteLine( "The number is not 1 or 2." );
break;
}, The code segment has valid syntax and no logic errors. :
n = 1;
while ( n < 10 )
Console.WriteLine( n++ );




11. Assume that the variable x has been declared, but not initialized. Select the phrase that describes the effect of each these proposed C# statements or groups of statements.
A. This code prints a newline character if x is evenly divisible by 5. If it is not, a tab character is printed.
B. A statement that prints an integer and advances to a new line.
C. The control statement of a for loop that loops 20 times. The counter variable is x.
D. A statement that prints an integer but does not advance to the next line.
E. The code has invalid syntax.
F. The number 2.5 is raised to the power of 3.
G. The statement has valid syntax, but does none of the above.
H. The control statement of a while loop that loops 20 times. The counter variable is x.
I. The number 3 is raised to the power of 2.5.


ABCDEFGHIConsole.Write( x );
ABCDEFGHI
if ( x % 5 == 0 )
Console.WriteLine();
else
Console.Write('\t');
ABCDEFGHIfor ( x = 1; x <= 20; x++ )
ABCDEFGHIdouble result = math.Pow( 2.5, 3 );
ABCDEFGHIwhile ( x <= 20 )
Points Earned: 4.0/4.0
Correct Answer(s): The control statement of a while loop that loops 20 times. The counter variable is x. : while ( x <= 20 ), The control statement of a for loop that loops 20 times. The counter variable is x. : for ( x = 1; x <= 20; x++ ), The number 2.5 is raised to the power of 3. : double result = math.Pow( 2.5, 3 );, A statement that prints an integer but does not advance to the next line. : Console.Write( x );, This code prints a newline character if x is evenly divisible by 5. If it is not, a tab character is printed. :
if ( x % 5 == 0 )
Console.WriteLine();
else
Console.Write('\t');




12. Select the best word or operator to fill the blank.
A. before
B. dynamic
C. true
D. switch
E. while
F. if
G. for
H. continue
I. break
J. static
K. &&
L. false
M. after
N. ||


ABCDEFGHIJKLMNTypically, ____ statements are used for sentinel-controlled repetition.
ABCDEFGHIJKLMNThe ___ statement, when executed in a repetition statement, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.
ABCDEFGHIJKLMNTypically, ____ statements are used for counter-controlled repetition.
ABCDEFGHIJKLMNIf the loop-continuation condition in a for header is initially ____, the for statement's body does not execute.
ABCDEFGHIJKLMNMethods that perform common tasks and do not need to be called on objects are called ____ methods.
ABCDEFGHIJKLMNThe ____ operator can be used to ensure that two conditions are both true before choosing a certain path of execution.
ABCDEFGHIJKLMNThe ____ statement selects among multiple actions based on the possible values of an integer variable or expression.
ABCDEFGHIJKLMNThe do...while statement tests the loop-continuation condition ____ executing the loop's body.
Points Earned: 7.0/7.0
Correct Answer(s): for : Typically, ____ statements are used for counter-controlled repetition., while : Typically, ____ statements are used for sentinel-controlled repetition., after : The do...while statement tests the loop-continuation condition ____ executing the loop's body., switch : The ____ statement selects among multiple actions based on the possible values of an integer variable or expression., continue : The ___ statement, when executed in a repetition statement, skips the remaining statements in the loop body and proceeds with the next iteration of the loop., && : The ____ operator can be used to ensure that two conditions are both true before choosing a certain path of execution., false : If the loop-continuation condition in a for header is initially ____, the for statement's body does not execute., static : Methods that perform common tasks and do not need to be called on objects are called ____ methods.

1 comment:

  1. According to Stanford Medical, It is indeed the one and ONLY reason this country's women live 10 years more and weigh 19 kilos less than we do.

    (And realistically, it is not related to genetics or some secret diet and absolutely EVERYTHING around "how" they are eating.)

    BTW, What I said is "HOW", not "what"...

    Click this link to find out if this little quiz can help you release your true weight loss potential

    ReplyDelete