Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to access the element at index 2 in the array.
DSA Java
int[] numbers = {10, 20, 30, 40, 50};
int value = numbers[[1]];
System.out.println(value);Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 instead of 2, which accesses the fourth element.
Forgetting that array indexes start at 0.
✗ Incorrect
The index 2 accesses the third element in the array, which is 30.
2fill in blank
mediumComplete the code to update the element at index 1 to 99.
DSA Java
int[] data = {5, 10, 15, 20};
data[[1]] = 99;
System.out.println(java.util.Arrays.toString(data));Attempts:
3 left
💡 Hint
Common Mistakes
Updating index 0 instead of 1.
Using an index out of array bounds.
✗ Incorrect
Index 1 refers to the second element, which is updated to 99.
3fill in blank
hardFix the error in the code to correctly update the last element of the array.
DSA Java
int[] arr = {2, 4, 6, 8};
arr[[1]] = 10;
System.out.println(java.util.Arrays.toString(arr));Attempts:
3 left
💡 Hint
Common Mistakes
Using index 4 which is out of bounds.
Confusing array length with last index.
✗ Incorrect
The last element is at index 3 because array indexes start at 0.
4fill in blank
hardFill both blanks to access and update the element at index 0 to 100.
DSA Java
int[] values = {7, 14, 21};
values[[1]] = [2];
System.out.println(java.util.Arrays.toString(values));Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong index like 1 or 2.
Assigning wrong value like 50 instead of 100.
✗ Incorrect
Index 0 accesses the first element, which is updated to 100.
5fill in blank
hardFill all three blanks to update the element at index 2 to 77 and print it.
DSA Java
int[] nums = {11, 22, 33, 44};
nums[[1]] = [2];
System.out.println(nums[[3]]);Attempts:
3 left
💡 Hint
Common Mistakes
Using different indexes for update and print.
Assigning wrong value instead of 77.
✗ Incorrect
Index 2 is updated to 77, then printed from the same index.
