Declare and Print Array in Java: Explanation & Practice
Create and display array elements
Problem summary
Create an array of 5 integers and print all elements.
Starter code
public class Main {
public static void main(String[] args) {
// Declare array with values: 10, 20, 30, 40, 50
// Print each element on a new line
}
}Expected output and test cases
- Print all elements
10 20 30 40 50
Hints
- int[] arr = {10, 20, 30, 40, 50};
- Use for loop to iterate
- Access elements with arr[i]
Related Arrays exercises
Practice all Arrays exercises · Run this idea in the Java compiler