
Unit #6 quiz 1
Authored by Michael Courtright
Computers
11th Grade
Used 2+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
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.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
15 questions
Pentaksiran T4(1.6)
Quiz
•
11th Grade
16 questions
Hour_of_Code
Quiz
•
5th - 12th Grade
10 questions
Programming with C++
Quiz
•
9th - 12th Grade
18 questions
GCSE OCR Python Paper 2 Basics
Quiz
•
11th Grade
10 questions
Latihan Interface
Quiz
•
9th - 12th Grade
11 questions
Programming basics
Quiz
•
10th - 11th Grade
13 questions
LENGUAJE C
Quiz
•
11th Grade
11 questions
Programming Quiz 1
Quiz
•
11th Grade
Popular Resources on Wayground
8 questions
Spartan Way - Classroom Responsible
Quiz
•
9th - 12th Grade
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
14 questions
Boundaries & Healthy Relationships
Lesson
•
6th - 8th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
3 questions
Integrity and Your Health
Lesson
•
6th - 8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
9 questions
FOREST Perception
Lesson
•
KG
20 questions
Main Idea and Details
Quiz
•
5th Grade