Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 Which loop control structure is used to create a data validation loop in the example in the additional reading on loops?? a while

Question 1

Which loop control structure is used to create a data validation loop in the example in the additional reading on loops??

a while loop
a do...while loop
a for loop

Question 2

A loop that uses an exit sentinel or exit code is what kind of loop?

a definite loop
an indefinite loop

Question 3

What will be printed by the following code? int bart = 6; int marge = 2; int lisa = 20; for ( int homer = 5; homer > 0; homer-- ) {

if ( bart < lisa )

bart = bart + marge * homer;

} System.out.println( bart );

6
10
18
24
36

Question 4

What will be printed by the following code? int bit = 6; int mit = 2; int lit = 20; for ( int hit = 1; hit <= 5; hit++ ) {

if ( bit < lit )

bit += mit * hit;

} System.out.println( bit );

6
8
18
26
36

Question 5

In Question 4's program, which variable is an accumulator?

bit
hit
lit
mit

Question 6

In Question 4's program, which variable is the loop control variable?

bit
hit
lit
mit

Question 7

What will be printed by the following code? int x; for ( x = 2; x < 10; x = x * x )

System.out.print( x + " " );

System.out.println( "Final x = " + x );

2 4 6 8 Final x = 10
2 4 Final x = 4
2 4 Final x = 10
2 4 Final x = 16
None of the above

Question 8

What will be printed by the following code? int x; for (x = 11; x <= 15; x++) {

if (x % 2 == 0)

System.out.print("S ");

else

System.out.print("D ");

}

S D S D S
D S D S D
S S S S S
D D D D D

Question 9

What will be printed by the following code? (This code is DIFFERENT from the previous problem!) int x; for (x = 11; x <= 15; x++) {

if (x / 12 == 0)

System.out.print("S ");

else

System.out.print("D ");

}

D D D D D
S D D D D
S S D D D
S S S D D
D S S S S

Question 10

What will be printed by the following code? int x = 5; while ( x > 0 ) {

System.out.print( x + " " ); x -= 2;

} System.out.println( "Final x = " + x );

Final x = -1
1 Final x = -1
5 3 1 Final x = 1
5 3 1 Final x = 0
5 3 1 Final x = -1

Question 11

What will be printed by the following code? (This code is DIFFERENT from the previous problem!) int x = 5; while ( x < 0 ) {

System.out.print( x + " " ); x -= 2;

} System.out.println( "Final x = " + x );

Final x = 5
5 Final x = 0
5 3 1 Final x = -1
5 3 1 Final x = 0
5 3 1 Final x = -1

Question 12

What will be printed by the following code? int x = 5; do {

System.out.print( x + " " ); x -= 2;

} while ( x < 0 ); System.out.println( "Final x = " + x );

Final x = 5
5 Final x = 3
5 3 1 Final x = 1
5 3 1 Final x = 0
5 3 1 Final x = -1

Question 13

What sequence of characters marks the beginning of a JavaDoc comment?

/*
/**
//
None of the above

Question 14

Which of the following is a Javadoc tag?

@javadoc
@public
@param
All of the above
None of the above

Question 15

Which part of the following code will NOT be executed due to "short circuit evaluation"? String name = "Homer"; if ( name.length() > 4 || name.equals("Bart") ) {

System.out.println("Doh!");

} System.out.println("Done");

String name = "Homer";
name.length() > 4
name.equals("Bart ")
System.out.println("Doh!");
System.out.println("Done");

Question 16

The program below produces this output: Cougs! Go Cougs! Go Cougs! Go Cougs! The code demonstrates what kind of pattern, described in Chapter 5 in the text? String team = "Cougs!"; System.out.print(team); for ( int i = 0; i < 3; i++ ) {

System.out.print(" Go "); System.out.print(team);

} System.out.println();

fencepost
team spirit
indefinite loop
random number
assertion

Question 17

In which package is the File class located?

java.awt
java.io
java.lang
java.util
javax.swing

Question 18

An exception that must be "handled" -- either caught or specifically declared (using a throws clause) in the header of any method that might generate it -- is called what?

a handled exception
a serious exception
a runtime exception
a checked exception
a throws exception

Question 19

Which of the following is a boolean (or predicate) method in the Scanner class that can "look-ahead" and reveal some information about the next token available in the stream?

hasNext()
hasNextDouble()
hasNextInt()
hasNextBoolean()
All of the above

Question 20

In the code snippet below, which class is the client and which class is the supplier? public class Paddle {

public static void someMethod(){

Fiddle f = new Fiddle();

...

}

... }

Paddle is the client, Fiddle is the supplier
Fiddle is the client, Paddle is the supplier
Both Paddle and Fiddle are clients
Both Paddle and Fiddle are suppliers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

In bargaining, does it really matter who makes the first offer?

Answered: 1 week ago