Consider the following loop which is an inefficient at best


1.Consider the following loop which is an inefficient (at best) attempt to increment count 200 times:
for ( k = 0; k < 200; k++);
count++;
Check all true statements (there will be more than one).
Remember: all variables are assumed to be declared prior to the loop, as needed.
A.It has a compiler error because of the extra semicolon.
B.It has a logic error because of the extra semicolon.
C.It has no compiler errors.
D.It has both compiler and run-time errors.

2.At the end of the third (3rd) loop pass of the following loop:
int count = -2;
for (int k = 3; k < 10; k++)
count++;
what is the value of count?
5
3
1
9

3.Consider the statement:
if ( (ans == 'Y' || errors < 5) &&numTries< 10 ) // note uppercase 'Y'
count++;
Which combinations of values results in count being incremented after the statement is complete?
(Select all that apply.)
A.ans = 'N'
errors = 3
numTries = 10
B.ans = 'y' (lower case)
errors = 4
numTries = 5
C.ans = 'Y' (upper case)
errors = 6
numTries = 5
D.ans = 'N'
errors = 5
numTries = 5
E.ans = 'Y' (upper case)
errors = 100
numTries = -1

4.For the two code segments below:
Segment A
int q = 5;
switch(q)
{
case 1:
System.out.println(1);
case 2:
System.out.println(2);
case 3:
System.out.println(3);
case 4:
System.out.println(4);
case 5:
System.out.println(5);
default:
System.out.println("default");
}
Segment B
q = 4;
switch(q)
{
case 1:
System.out.println(1);
case 2:
System.out.println(2);
case 3:
System.out.println(3);
case 4:
System.out.println(4);
case 5:
System.out.println(5);
default:
System.out.println("default");
}

Which of the following statements is true?

A.The output for Segment A is:
default

B.The output for Segment B is:
4

C.The output for Segment B is:
45default

D.The output for Segment A is:
5
default

5. What will be the value of x after the following code is executed?
int x = 10;
while (x < 50)
{
x -= 10;
}

A.40
B.50
C.60
D.10

6. What output will be produced by the following code?

intevenNumber = 2;
do
{
System.out.println(evenNumber);
evenNumber += 2;
}while(evenNumber< 10);

A. 2,4,6,8,10

B.2,4,6,8

C.2,4,6

D.0,2,4,6,8,10

7. Consider the following snippet of code:
intfirstNum = 5;
intsecondNum = firstNum++;
intthirdNum = 6 * (++firstNum);

What values are stored in firstNum and secondNum after these lines are executed

A.secondNum will contain 6 and firstNum will contain 5.

B.secondNum will contain 5 and firstNum will contain 6.

C.secondNum will contain 4 and firstNum will contain 5.

D.secondNum will contain 5 and firstNum will contain 4.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Consider the following loop which is an inefficient at best
Reference No:- TGS02386326

Now Priced at $20 (50% Discount)

Recommended (94%)

Rated (4.6/5)