0
0
Javaprogramming~15 mins

Common array operations in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an integer array of size 5.

Java
int[] numbers = new int[[1]];
🎯 Drag options to blanks, or click blank then click option
A1
B10
C0
D5
Attempts:
3 left
2fill in blank
medium

Complete the code to access the third element of the array.

Java
int third = numbers[[1]];
🎯 Drag options to blanks, or click blank then click option
A2
B3
C1
D0
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to correctly print all elements of the array.

Java
for (int i = 0; i < numbers.[1]; i++) {
    System.out.println(numbers[i]);
}
🎯 Drag options to blanks, or click blank then click option
Alength()
Bsize()
Clength
Dcount
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create an array of squares for numbers 1 to 5.

Java
int[] squares = new int[5];
for (int [1] = 0; [2] < 5; [1]++) {
    squares[[1]] = ([1] + 1) * ([1] + 1);
}
🎯 Drag options to blanks, or click blank then click option
Ai
Bj
Ck
Dx
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a new array with elements doubled from the original.

Java
int[] doubled = new int[numbers.[1]];
for (int [2] = 0; [2] < numbers.length; [2]++) {
    doubled[[2]] = numbers[[2]] [3] 2;
}
🎯 Drag options to blanks, or click blank then click option
Alength
Bi
C*
D+
Attempts:
3 left