Unit #6 quiz 1

Unit #6 quiz 1

11th Grade

13 Qs

quiz-placeholder

Similar activities

Unit 9 AP CSA Inheritance

Unit 9 AP CSA Inheritance

10th - 12th Grade

8 Qs

APCSA Inheritance, Superclass, Subclass

APCSA Inheritance, Superclass, Subclass

10th - 12th Grade

8 Qs

AP CSA Arrays

AP CSA Arrays

10th - 12th Grade

14 Qs

Exploring Computer Science

Exploring Computer Science

10th - 12th Grade

14 Qs

Traversing Arrays

Traversing Arrays

10th - 12th Grade

14 Qs

QUIZ #1 JAVASCRIPT

QUIZ #1 JAVASCRIPT

11th Grade

16 Qs

Java Lab Code.org AP CSA

Java Lab Code.org AP CSA

9th - 12th Grade

18 Qs

SC025 WEEK 4

SC025 WEEK 4

11th - 12th Grade

14 Qs

Unit #6 quiz 1

Unit #6 quiz 1

Assessment

Quiz

Computers

11th Grade

Hard

Created by

Michael Courtright

Used 2+ times

FREE Resource

13 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Read the following code segment.

String[] str1 = new String[2];

String[] str2 = {"Mike","Rony","August"};

str1 = str2; System.out.println(str1.length);

What is printed as a result of executing the code segment?

0

2

3

null

compile time error

Answer explanation

String is an immutable class. Assigning a new value to a String object will create a new reference.

2.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

void my(){ int[] arr = {13,15,25,12,34,55,11,10,17};

int count=0;

for(int num : arr) // check the divisibilty by 5

System.out.println(count); }

The method my() is intended to display the number of array elements that are divisible by 5. Which of the following code segments could be used to replace // check the divisibility by 5 so that my() will work as intended?

if( arr % 5 == 0) count++;

if( num[arr] % 5 == 0) count++;

if( arr[i] % 5 == 0) count++;

if( num % 5 == 0) count++;

if( arr[num] % 5 == 0) count++;

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which of the following is stored in arrays and provides access to the values stored in the memory?

primitive data types

classes

parameters

methods

reference data types

Answer explanation

In Java, arrays are container objects of reference data types that can hold a fixed number of values of a single type. The length of an array is defined when the array is created. After creation, its length is fixed.

4.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

int a[] = {5,6,12,3,4,5,18};

int num = a[0];

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

{ if(num < a[i]) { num = a[i]; } } System.out.println(num);

What is printed as a result of executing the code segment?

3

5

7

18

compile time error

Answer explanation

This code is finding the largest array element, assuming that num is the largest with zero initially and then comparing with other elements one by one. If any array element is larger than num, the larger value is assigned to num.

5.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

When an array is passed as an argument, what kind of value is passed to the calling method?

name of the array

value of the first element

length of the array

reference of the array

copy of the array

Answer explanation

An array is passed with the reference of the array. Any change in the formal array will modify the actual array in the calling method.

6.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which of the following is/are true for an array with methods?

I. Multiple arrays can be passed as an argument.

II. A method can return an array.

III. There are no square brackets with an array name while calling the method that has an array as a parameter.

I only

II only

I and II

I and III

I, II, and III

Answer explanation

All of the statements are true with respect to arrays with Java methods.

You can have multiple arrays that can be passed as an argument.

A Java method can return an array.

You should not put square brackets with an array name while calling the method that has an array as a parameter.

7.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

The following code segment was written to modify array elements by replacing all odd numbers with 0.

int modarr[] = {2,3,4,5,12};

for(int temp : modarr){

if(temp%2 != 0) temp = 0; }

for(int temp : modarr) System.out.print(temp + " ");

What is printed as a result of executing the code segment?

0 3 0 5 0

'2' '0' '4' '0' '0'

2 0 4 0 12

2 3 4 5 12

compile time error

Answer explanation

The for each loop cannot modify the contents of the actual array, as the iteration object is just a copy of a single array element. The variable temp will be modified, but not the array element.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?