1) What will be printed by the following code? int x = 5; while ( x < 0 ) { Syst
ID: 3833101 • 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();
...
}
...
}
Explanation / Answer
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 );
Answer :
a)
Final x = 5
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 );
Answer
5 Final x = 3
3) What sequence of characters marks the beginning of a JavaDoc comment?
Answer;
/*
4)Which of the following is a Javadoc tag?
c)@param
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");
Answer:
System.out.println("Doh!"); will not be executed if the condition is true
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();
Answer:
fencepost
7) In which package is the File class located?
Answer)
java.io
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?
Answer : checked exception
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?
Answer: All the above
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();
...
}
...
}
Answer
Paddle is the supplier and Fiddle is the client
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.