Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 11 What are the values of i and sum after this code sequence is executed? int i = 0; int sum = 0; for

Question 11

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 41 sum is 60

c.

i is 40 sum is 100

d.

i is 41 sum is 100

2.5 points

Question 12

What is the output of the following code sequence:

double a = 16 / 5; System.out.println( a );

a.

2.6

b.

3.2

c.

a

d.

3.0

2.5 points

Question 13

Given code:

public abstract class A{ } public class B extends A { }

The following code sequence would correctly create an object reference of class A holding an object reference for an object of class B:

A c; c = new B();

True

False

2.5 points

Question 14

Given the following code declaring and initializing two int variables x and y with respective values 7 and 9, answer question 14 indicating whether the value of the expression is true or false.

int x = 7; int y = 9;

Expression: ( y x == 0 || ( x + 2 ) != y)

True

False

2.5 points

Question 15

Class SimpleDate encapsulates integer instance variables month, day and year. Consider the following equals method in class SimpleDate:

public boolean equals( Object o ) { if ( !( d instanceof SimpleDate ) )

return false;

( Insert appropriate code from selections below)

if ( month == d1.month

&& day == d1.day && year == d1.year )

return true;

else

return false;

}

Which statement(s) could be used to complete the above method body code correctly?

a.

SimpleDate d1; d1 = (SimpleDate)o;

b.

SimpleDate d1 = o;

c.

SimpleDate d1 = (SimpleDate)o;

d.

Both a and c

2.5 points

Question 16

Which of the following is not a valid wrapper class?

a.

Integer

b.

Double

c.

Char

d.

Boolean

2.5 points

Question 17

What is the output of this code sequence:

double [ ][ ] a =

{{ 12.5, 48.3, 65.0, 77.1 }, { 65.0, 48.3, 12.5}};

System.out.println( a[1][ 3 ] );

a.

An ArrayIndexOutOfBounds exception would be thrown.

b.

77.1

c.

65.0

d.

12.5

2.5 points

Question 18

What is the output of this code sequence?

double [ ] [ ] a =

{{ 100.4, 99.6, 48.2, 65.8 }, { 100.5, 99.7, 48.2, 65.8 }};

double temp = a[0][1];

for ( int i = 1; i < a.length; i++ )

for ( int j = 1; j < a[i].length; j++ )

{

if ( a[i][j] > temp )

temp = a[i][j];

}

System.out.println( temp );

a.

99.6

b.

100.4

c.

99.7

d.

100.5

2.5 points

Question 19

Which statement(s) will instantiate a double array of 6 total elements?

a.

double [] [] cellbills = new double[2][]; cellbills[0] = new double[4]; cellbills[1] = new double[2];

b.

double [] [] cellbills = { { 45.24, 54.67, 42.55, 44.61, 65.29 }, { 7 } };

c.

Both a and b

d.

None of the above

2.5 points

Question 20

Given an array int a [][] = new int[3][4] ,how do you access the element of array a located in the third row and the fourth column?

a.

a[3][4]

b.

a( 2,3 )

c.

a{3}{4}

d.

a[2][3]

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

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

2. Enrolling employees in courses and programs.

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago