0
0
Javaprogramming~15 mins

Array length property in Java - Practice Problems & Coding Challenges

Choose your learning style8 modes available
trophyChallenge - 5 Problems
🎖️
Array Length Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate
2:00remaining
What is the output of this Java code using array length?
Consider the following Java code snippet. What will be printed when it runs?
Java
public class Main {
    public static void main(String[] args) {
        int[] numbers = {5, 10, 15, 20, 25};
        System.out.println(numbers.length);
    }
}
A6
B5
CCompilation error
D4
Attempts:
2 left
💻 code output
intermediate
2:00remaining
What is the output when accessing length of a multidimensional array?
Look at this Java code. What will it print?
Java
public class Main {
    public static void main(String[] args) {
        int[][] matrix = new int[3][4];
        System.out.println(matrix.length);
    }
}
A3
B4
C7
DRuntime error
Attempts:
2 left
💻 code output
advanced
2:00remaining
What happens if you try to assign to the length property of an array?
What will happen when this Java code runs?
Java
public class Main {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        arr.length = 5;
        System.out.println(arr.length);
    }
}
ARuntime exception
B5
C3
DCompilation error
Attempts:
2 left
💻 code output
advanced
2:00remaining
What is the output of this code accessing length of a null array?
What will this Java program print or do?
Java
public class Main {
    public static void main(String[] args) {
        int[] arr = null;
        System.out.println(arr.length);
    }
}
A0
BCompilation error
CNullPointerException at runtime
DPrints 'null'
Attempts:
2 left
🧠 conceptual
expert
2:00remaining
How many elements are in the array after this code runs?
What is the number of elements in the array 'data' after executing this code?
Java
public class Main {
    public static void main(String[] args) {
        int[] data = new int[10];
        data = new int[5];
        System.out.println(data.length);
    }
}
A5
B10
C15
DCompilation error
Attempts:
2 left