How do you output the data in an array using Java?
In Java, loops can be used to print out the data in an array. Here is an example code:
public class Main {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
Running the code above will display the data in the array arr.
1
2
3
4
5