Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3831487 • Letter: 1

Question

1) 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 );

5 3 1 Final x = -1

2) 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 );

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

4) Which of the following is a Javadoc tag?

5) 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");

6) 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();

7) In which package is the File class located?

8) 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?

9) 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?

10) 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();

...

}

...
}

a) Final x = 5

Explanation / Answer

1) The anwer is a. As initially x=5, the loop is not entered as x<0 will be false.

2) The answer is b. The loop is entered and it prints 5 and then x becomes 3 and as x<0 is false. The loop is exited.

3) The answer is c.

4) The answer is c.