WorksheetsArrays
Total questions: 14
Worksheet time: 7mins
Which of the following is FALSE about arrays on Java
A java array is an object
Length of array can be changed after creation of array
Numerical data types of arrays are initialized to 0 to start
Find the output
class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
Compile error
Exception
Garbage Value
Garbage Value
0
0
Find the output
class Test {
public static void main(String args[]) {
int [ ] arr = new int[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
Compile error
Exception
Garbage Value
Garbage Value
0
0
What is the length of the following array: int [] data = { 12, 34, 9, 0, -62, 88 };
1
5
6
12
Output of following Java program?
class Test{
public static void main (String[] args) {
int [] arr1 = {1, 2, 3};
int [] arr2 = {1, 2, 3};
if (arr1 == arr2)
System.out.println("Same");
else
System.out.println("Not same");
}}
Same
Not same
Error
What are the indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 }
0, 1, 2, 31, 2, 3, 40, 2, 4, 6What is the error in the following code fragment?
double [] average = new double [20];
average[20] = 15.25;
A cast is required
data not initialized
A two-dimensional array is required
Array Out-of-bounds error
what is the result of :
nums[1]+nums[3]
3
14
6
5
System.out.println("Number: " + numArray[numArray.length - 1]);
int[] numbers = new int[5];
True or False: A single array can be used to store different primitive data types
