
Unit #6 quiz 1

Quiz
•
Computers
•
11th Grade
•
Hard
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
Similar Resources on Wayground
17 questions
Arrays recap

Quiz
•
9th Grade - University
11 questions
S4: Arrays and Input Validation

Quiz
•
11th Grade
11 questions
Array C++

Quiz
•
11th Grade
14 questions
APCSA Unit 6 Review Arrays

Quiz
•
10th - 12th Grade
12 questions
C# Arrays

Quiz
•
9th - 12th Grade
18 questions
UH1 - Loop dan Array

Quiz
•
11th Grade
18 questions
Motherboard Form Factors & Overview

Quiz
•
6th - 12th Grade
14 questions
AP CSA Review

Quiz
•
11th Grade
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade