Font size
WorksheetsArrays in Java
Total questions: 20
Worksheet time: 11mins
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
class Demo1
{
public static void main(String args[])
{
int i[] = new int[0];
System.out.println(i[0]);
}
}
0
Exception
Garbage value
class Demo1
{
public static void main(String args[])
{
int i[] = new int[10];
System.out.println(i[10]);
}
}
0
Garbage value
Out of bound exception
Error
How will you identify a single dimensional array?
single curly brackets
single square brackets
multiple squares brackets
single angled brackets
If the data is in order the best search to use would be a______
Binary Search
Linear Search
What is returned by values[5]?
2
12
6
8
Which option represents: An array holding String data?
var names = {"Raj", "Simran", "Divya"};
var names = {Raj, Simran, Divya};
ar nums ={2, 3, 5, 8, 9, 11};
How would you access the second element in nums
num(2)
num[2]
num(1)
num[1]
What is the result of :
nums[1]+nums[3]
3
14
6
5
What will be the array after executing this line ?
names[1] = "Sarah";
What does the following segment of code print out?
int[] numArray = { 2, 7, 4, 12, 0, 2 };
System.out.println("Number: " + numArray[numArray.length - 1]);
Number: 2
Number: 0
Number: 12
Number: 6
What is the correct way to initialize an array with 10 positions?
int numbers = new int[10];
int[] numbers = new int[];
int[] numbers = new int[10];
int[10] numbers = new int[10];
What value is stored in each of the 5 positions in this array?
String[] numbers = new String[5];
null
1
0
nothing
What is an Array?
Variable
Data type
Pointer
String
The total number of elements in the array is called...............
index
length
subscript
memory
for(int i=0; i<10; i++)
numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 5?
1
2
3
4
What will be the memory size of the array given below:
double[] fees = new double[15];
What will be the memory size of the array given below:
int[][] num = new int[3][5];
In an array, the index of the first element is (a)
