NEW
Font size
WorksheetsCSA Unit 3 Review
Total questions: 20
Worksheet time: 17mins
double[ ] data = new double[10];
double[ ] data = new double[20];
data[20] = 15.25;
What is word.length()?
What is word.charAt(7) ?
String word = "A few good men";
What is word.indexOf('f')?
What is word.indexOf(“bad”)?
What is word.substring(3, 7) ?
What are the indexes for the array arr, given the following declaration:
int[] arr = {2, 4, 6, 8 }
0, 1, 2, 31, 2, 3, 40, 2, 4, 6What is the output of the following code fragment:
int[] arr = {2, 4, 6, 8 };
System.out.println( arr[0] + " " + arr[1] );
2 62 46 8In the given code segment, assume String str has been declared and initialized. The code is supposed to print the number of Strings in the array animals that have str as a substring. The code does not work as intended. Which of the following changes should be made so the code works as intended.
The stopping condition should be changed to i < animals.length
The stopping condition should be changed to i < animals.length - 1
The stopping condition should be changed to i < animals[i].length
The if statement should be changed to animals[i].equals(str)
String sentence = "Hello World!";
What is sentence.indexOf("W")?
6
5
7
-1
Given an array int[] numbers = {10, 20, 30, 40};
What is the value of numbers[2]?
10
20
30
40
What is the output of the following code fragment:
String[] fruits = {"apple", "banana", "cherry"};
System.out.println(fruits[1]);
apple
banana
cherry
fruits
How would you get the value 6 out of the following array int[][] a = { {2, 4, 6, 8}, {1, 2, 3, 4}};?
a[0][3]
a[1][3]
a[0][2]
a[2][0]
a[3][1]
Given the following code segment, what is the value of sum after this code executes?
4
8
9
12
10
What are the contents of arr after the following code has been executed?
{ {6, 4, 2}, {2, 4, 6}}
{ {3, 2, 1}, {1, 4, 6}}
{ {3, 2, 1}, {1, 4, 8}}
{ {4, 4, 2}, {2, 4, 4}}
{ {3, 2, 1}, {2, 4, 4}}
