Question
1. In the Quiz class, the foo method has the following API: public char foo( int i, String s, double c ) Which method call(s)
1. In the Quiz class, the foo method has the following API:
public char foo( int i, String s, double c )
Which method call(s) could be correct assuming a is an int and y is an int and each statement is complete?
a. | Quiz q = new Quiz(); a = Quiz.foo( y, Maybe?, 1.0 ); | |
b. | char c = Quiz.foo( 1, Hmmm!, 0.1 ); | |
c. | Quiz q = new Quiz(); System.out.println( q.foo( y, You think., 2.0)); | |
d. | All of the above |
2.
What is the output of the following code sequence?
String s = Hello World Again;
s = s.toLowerCase( );
System.out.println(s.charAt(5));
a. | a space is printed | |
b. | W | |
c. | Hello | |
d. | o |
3.
What is the output of the following code sequence?
String weather = new String("Sun is NOT Shining");
String day = "NOT Sunday after lunch";
if(!(weather.equals("Sun is NOT Shining") && day.equals("NOT Sunday after lunch")))
{
System.out.println("Read a book");
}
else
{
System.out.println("Go sailing");
}
a. | Read a book | |
b. | Go sailing | |
c. | Read a book Go sailing | |
d. | none of the above |
4.
What is the output of the following code sequence?
int grade = 69; if ( grade >= 90 ) System.out.println( A ); else if ( grade >= 80 ) System.out.println( B ); else if ( grade >= 70 ) System.out.println( C ); else System.out.println( D or Lower ); System.out.println(Done);
a. | C Done | |
b. | D or Lower | |
c. | Done | |
d. | D or Lower Done |
5.
What is the output of the following code sequence?
int season = 0; switch ( season ) { case 1: System.out.println( Season is Summer); break; case 2: System.out.println( Season is Fall); case 3: System.out.println( Season is Winter); case 4: System.out.println( Season is Spring); break; default: System.out.println( End of Seasons); }
a. | Season is Fall Season is Winter Season is Spring | |
b. | End of Seasons | |
c. | Season is Summer Season is Fall Season is Winter Season is Spring | |
d. | Season is Summer |
6.
Given the following code declaring and initializing three boolean variables x, y and z with respective values true, true, and false, does the following expression evaluate to true or false?
boolean x = true; boolean y = true; boolean z = false;
Expression: ((x || y) && !z)
True
False
7.
Given the following code declaring and initializing three boolean variables x, y and z with respective values true, true, and false, does the following expression evaluate to true or false?
boolean x = true; boolean y = true; boolean z = false;
Expression: ((x && z) || y)
True
False
8.
Given the following code declaring and initializing two int variables x and y with respective values 19 and 17, does the value of the expression evaluate to true or false.
int x = 19; int y = 17;
Expression: x > y || !( x>y )
True
False
9.
Given the following code declaring and initializing two int variables x and y with respective values 19 and 17, does the value of the expression evaluate to true or false.
int x = 19; int y = 17;
Expression: y >= 17
True
False
10.
Given the following code declaring and initializing two int variables x and y with respective values 19 and 17, does the value of the expression evaluate to true or false.
int x = 19; int y = 17;
Expression: ( x - 2 == y ) && ( y>x )
True
False
11.
Given two boolean expressions a and b, are the following expressions equivalent?
!( a && b ) !a || !b
True
False
12.What are the values of i and product after this code sequence is executed?
int i = 6; int product = 1; do
{
product*=i;
i++
}while (i<=9;
a. | i is 9 product is 336 | |||||||||||||
b. | i is 8 product is 42 | |||||||||||||
c. | i is 8 product is 14 | |||||||||||||
d. | d. i is 10 product is 3024 13. What are the values of i and sum after this code sequence is executed? int i = 0; int sum = 0; for ( i = 0; i < 40; i++) {
if ( i % 10 = = 0)
sum += i ; }
|
14.
If you want to execute a loop body at least once, what type of looping structure would you use?
a. | for loop | |
b. | while loop | |
c. | do/while loop | |
d. | none of the above |
15.
What is the output of this code sequence? (The user successively enters 3, 5, and -1.)
System.out.print( Enter an int > ); int i = scan.nextInt( ); while ( i != -1)
{
System.out.print( Enter an int > ); i = scan.nextInt( ); System.out.println( Hello );
}
a. | Enter an int > 3 Hello Enter an int > 5 Hello Enter an int > -1 | |
b. | Hello Enter an int > 3 Hello Enter an int > 5 Hello Enter an int > -1 | |
c. | Enter an int > 3 Enter an int > 5 Hello Enter an int > -1 Hello | |
d. | none of the above |
True or false. You can simulate a for loop with a while loop?
True
False
16.
What are the values of i and sum after this code sequence is executed?
int i = 0; int sum = 0; while ( i < 7 ) {
sum += i; ++i;
}
a. | i is 6 sum is 21 | |||||||||||||||||||||||||||||||||||||||||||||||||
b. | i is 8 sum 21 | |||||||||||||||||||||||||||||||||||||||||||||||||
c. | i is 7 sum is 21 | |||||||||||||||||||||||||||||||||||||||||||||||||
d. | i is 6 sum is 15 17. In the Quiz class, the foo method has the following API: public static double foo( float f ) What can you say about the method foo?
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started