The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Blehh
By Guest on 7th October 2024 07:41:43 AM | Syntax: PYTHON | Views: 45



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. import java.io.DataInputStream;
  2. import java.io.IOException;
  3.  
  4. public class ArrayDisplay {
  5.     public static void main(String[] args) {
  6.         int[] arr = new int[5];
  7.         DataInputStream dis = new DataInputStream(System.in);
  8.  
  9.         try {
  10.             System.out.println("Enter 5 elements:");
  11.             for (int i = 0; i < arr.length; i++) {
  12.                 arr[i] = Integer.parseInt(dis.readLine());
  13.             }
  14.  
  15.             System.out.println("The elements in the array are:");
  16.             for (int i = 0; i < arr.length; i++) {
  17.                 System.out.println(arr[i]);
  18.             }
  19.         } catch (IOException e) {
  20.             System.out.println("An input error occurred.");
  21.         } catch (NumberFormatException e) {
  22.             System.out.println("Please enter valid integer numbers.");
  23.         }
  24.     }
  25. }





blehh    





  • Recent Pastes