Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ;

}

a.

i is 40 sum is 60

b.

i is 39 sum is 40

c.

i is 40 sum is 40

d.

i is 39 sum is 60

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?

a.

it is an instance method

b.

it is a class field

c.

it is a class method

d.

it is an instance variable

18.

To instantiate an object instance of class SimpleDate assuming an overloaded SimpleDate class constructor requiring 3 int parameters exists, which statement(s) could be used to instantiate an object of type SimpleDate?

a.

SimpleDate s1 = SimpleDate(1, 2, 3);

b.

SimpleDate s2 = new SimpleDate(1, 2, 3);

c.

SimpleDate s3 = new SimpleDate();

d.

d. b and c

19.

What is the value of i and how many times will the word Hello have printed after this code sequence is executed?

int i = 0; for( i = 0; i < =2; i++) {

System.out.println( "Hello");

}

a.

i is 2 Hello prints 2 times

b.

i is 3 Hello prints 3 times

c.

i is 2 Hello prints 3 times

d.

i is 3 Hello prints 2 times

20.

What is output after the following code sequence is executed?

 float piF = 3.141592653589793f; // value assigned has float precision double piD = 3.141592653589793; // value assigned has double precision final double THRESHOLD = .0001; 
 if( piF == piD) 
 System.out.println( piF and piD are equal ); 
 else 
 System.out.println( piF and piD are not equal ); 
 if( Math.abs( piF  piD ) < THRESHOLD ) 
 System.out.println( piF and piD are considered equal ); 
 else 
 System.out.println( piF and piD are not equal ); 
a.

piF and piD are equal piF and piD are not equal

b.

piF and piD are equal piF and piD are considered equal

c.

piF and piD are not equal piF and piD are not equal

d.

piF and piD are not equal piF and piD are considered equal

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

Step: 3

blur-text-image

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

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

List the components of the strategic management process. page 72

Answered: 1 week ago