- import java.io.DataInputStream;
- import java.io.IOException;
- public class ArrayDisplay {
- public static void main(String[] args) {
- int[] arr = new int[5];
- DataInputStream dis = new DataInputStream(System.in);
- try {
- System.out.println("Enter 5 elements:");
- for (int i = 0; i < arr.length; i++) {
- arr[i] = Integer.parseInt(dis.readLine());
- }
- System.out.println("The elements in the array are:");
- for (int i = 0; i < arr.length; i++) {
- System.out.println(arr[i]);
- }
- } catch (IOException e) {
- System.out.println("An input error occurred.");
- } catch (NumberFormatException e) {
- System.out.println("Please enter valid integer numbers.");
- }
- }
- }