NEW
Font size
WorksheetsIPS_JAVA_Fall25_ Quiz9
Total questions: 12
Worksheet time: 6mins
Which of the following is the correct way to declare an array of integers in Java?
int array[];
int[] array;
array int[];
int array;
What is the default value of an element in a newly created integer array in Java?
1
0
null
-1
How do you access the third element of an array named `numbers` in Java?
numbers[2]
numbers[3]
numbers(3)
numbers{2}
Which statement correctly initializes an array of 5 doubles in Java?
double[] arr = new double[5];
double arr = new double[5];
double arr[5];
double[] arr = {5};
What is the length of the array `int[] arr = {1, 2, 3, 4, 5};`?
4
5
6
0
Which of the following statements assigns the value 10 to the first element of an array named `data`?
data[0] = 10;
data[1] = 10;
data(0) = 10;
data = 10[0];
Given `int[] arr = new int[3];`, which code segment will fill the array with the values 1, 2, and 3?
arr[0]=1; arr[1]=2; arr[2]=3;
arr[1]=1; arr[2]=2; arr[3]=3;
arr[0]=3; arr[1]=2; arr[2]=1;
arr[0]=2; arr[1]=3; arr[2]=1;
If you want to print all elements of an array `nums` of length 4, which loop is most appropriate?
for(int i=0; i
for(int i=1; i<=nums.length; i++) { System.out.println(nums[i]); }
for(int i=0; i<=nums.length; i++) { System.out.println(nums[i]); }
for(int i=1; i
Which of the following code snippets correctly creates and initializes an array of 3 strings with the values "A", "B", and "C"?
String[] arr = {"A", "B", "C"};
String arr = new String[3]{"A", "B", "C"};
String[] arr = new String("A", "B", "C");
String arr[] = new String[3];
Given `int[] values = {2, 4, 6, 8};`, what is the value of `values[values.length - 1]`?
2
4
6
8
Suppose you have an array `int[] arr = {5, 10, 15, 20, 25};`. Write a code segment to calculate the sum of all elements in the array.
int sum = 0; for(int i=0; i
int sum = arr[0] + arr[1] + arr[2];
int sum = arr.length;
int sum = arr[0] * arr[1] * arr[2];
Given an array `int[] nums = {3, 7, 2, 9, 4};`, which code finds the maximum value in the array?
int max = nums[0]; for(int i=1; i
int max = nums[0]; for(int i=0; i
int max = nums[0]; for(int i=1; i
int max = nums[0]; for(int i=0; i
